Php PDO wrong row count -
can explain me when echo $rows_affected variable, why 1 when should getting 2 based on db records? more half hour trying figure out , still cant solve it.. still noob on pdo.
any other advices welcome.
$sql1 = "select title page id=?"; $stm = $db->prepare($sql1); $stm->execute(array($id)); $row1 = $stm->fetch(pdo::fetch_assoc); $sql2 = "select id,title,pg_title page title=? order id asc"; $stm = $db->prepare($sql2); $stm->execute(array($row1['title'])); $rows_affected = $stm->fetchcolumn(); if (count($rows_affected) > 0) { for($i=0; $i <= $rows_affected; $i++) { $row2 = $stm->fetch(pdo::fetch_assoc); if($row2['id']==$id){ echo '<a href="javascript: void(0)"><b>'.$row2['pg_title'].'</b></a> '; }else{ echo '<a href="page.php?id='.$row2['id'].'';?><?php if(isset($_get['edit']) && $_get['edit']==1){ echo '&edit=1';}?><?php echo'">'.$row2['pg_title'].'</a> '; } } }
returns single column from next row of result set or false if there no more rows.
i think want use fetchall()
. use pdo::fetch_column
$fetch_style
if want first column. e.g.
$rows_affected = $stm->fetchall(pdo::fetch_column, 0);
Comments
Post a Comment