Prank Posted March 6, 2006 Share Posted March 6, 2006 Hi All,You can see the script functioning [a href=\"http://www.skylinesaustralia.com/trader_convert.php\" target=\"_blank\"]here[/a]But, if you click through a few pages, you'll see that the first record is never displayed. Ie, record 1, record 51, record 101 etc... I have no idea why... Heres my code;[code]//snipdb_connect();//if (!isset($_POST['screen'])) {// $screen = 0;//} else {$screen = $_REQUEST['screen'];$rows_per_page = 50;$start = $screen * $rows_per_page;$q = "SELECT * FROM user_rate_trade ORDER BY userrateid LIMIT $start , $rows_per_page";$r = mysql_query($q)or die(mysql_error());$row = mysql_fetch_assoc($r);while($row = mysql_fetch_assoc($r)) { $id = $row['userrateid']; $date = strtotime($row['userdate']); $to_id = $row['ratedused']; $userid = $row['userid']; if ($row['userrating'] == -1) { $rating = 2; } else if ($row['userrating'] == 0) { $rating = 3; } else if ($row['userrating'] == 1) { $rating = 1; } echo ''.$id.'. '.$row['userdate'].' = '.$date.' - Rating - '.$rating.'<br/>';}$newscreen = $screen + 1;echo ''.$q.'<br /><a href="trader_convert.php?screen='.$newscreen.'">Next</a>';[/code]Thanks for any help, it has me stumped.Christian Link to comment https://forums.phpfreaks.com/topic/4200-php-or-mysql-stripping-first-record-from-each-page/ Share on other sites More sharing options...
XenoPhage Posted March 6, 2006 Share Posted March 6, 2006 [code]$r = mysql_query($q)or die(mysql_error());$row = mysql_fetch_assoc($r);while($row = mysql_fetch_assoc($r)) {[/code]You have the above code. The reason you lose the first record is because of that first call to mysql_fetch_assoc. Change the code to this :[code]$r = mysql_query($q)or die(mysql_error());while($row = mysql_fetch_assoc($r)) {[/code] Link to comment https://forums.phpfreaks.com/topic/4200-php-or-mysql-stripping-first-record-from-each-page/#findComment-14631 Share on other sites More sharing options...
wickning1 Posted March 6, 2006 Share Posted March 6, 2006 It's amazing how often people make this mistake. mysql_fetch_array() iterates through a resource, every time you call it, you advance one record, so you don't want to call it until you're ready for a row. Link to comment https://forums.phpfreaks.com/topic/4200-php-or-mysql-stripping-first-record-from-each-page/#findComment-14640 Share on other sites More sharing options...
Prank Posted March 6, 2006 Author Share Posted March 6, 2006 Thanks guys! I should have picked that up.. Christian Link to comment https://forums.phpfreaks.com/topic/4200-php-or-mysql-stripping-first-record-from-each-page/#findComment-14860 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.