Jump to content

PHP or MySQL stripping first record from each page


Prank

Recommended Posts

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]
//snip

db_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
Share on other sites

[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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.