PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
$order='ASC';
$numRows =5;
if ($_SERVER['HTTP_CONNECTION']){
$limit = $numRows ;
$query_id_rs = "SELECT id FROM textads WHERE visible='y' AND active='y' ORDER BY date_created ".$order." LIMIT ".$limit."";
$id_rs = mysql_query($query_id_rs, $db_connect) or die(mysql_error());
$all_visible_ids = mysql_fetch_assoc($id_rs);
while($all_visible_ids = mysql_fetch_assoc($id_rs)){
$sql_query = 'UPDATE textads SET view_count = view_count+1 WHERE id="'.$all_visible_ids['id'].'"';
mysql_query($sql_query, $db_connect) or die(mysql_error());
// for testing
//print_r($all_visible_ids);
}
}
It seems to be dropping the first record and only increment to four records. I tried $limit = $numRows +1; and all that did was skip the first record in the fetch and add to 5 preceeding records.
WTF anyone know whats up with this little bug? How to work around it?
$all_visible_ids = mysql_fetch_assoc($id_rs); //This line calls your first row and puts it in $all_visible_ids
while($all_visible_ids = mysql_fetch_assoc($id_rs)){ //This gets 2-5 rows but over writes row 1
$sql_query = 'UPDATE textads SET view_count = view_count+1 WHERE id="'.$all_visible_ids['id'].'"';
mysql_query($sql_query, $db_connect) or die(mysql_error());
// for testing
//print_r($all_visible_ids);
}
}
Dunno what your trying to accomplish but the first row is being wiped out in the first line of code above. See my comments in the code.