Can someone explain me when i echo $rows_affected variable, why i only get 1 when I should be getting 2 based on my db records? More than half an hour trying to figure out this and still cant solve it.. Still noob on PDO.
Any other advices are welcome.
$sql1 = "SELECT title FROM page WHERE id=?";
$stm = $db->prepare($sql1);
$stm->execute(array($id));
$row1 = $stm->fetch(PDO::FETCH_ASSOC);
$sql2 = "SELECT id,title,pg_title FROM page WHERE title=? ORDER BY 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> ';
}
}
}