Jump to content

Help debuging LIMIT


jj20051

Recommended Posts

Alright so I have some code for pagination... the problem is on the middle pages it will display double the number of results... (IE if its supposed to display 5, it displays 10)

 

// Number of messages per page:
$user_message_number = 5;

$page = $_GET['page'];
if($page <= 1){
$low = 0;
$high = $user_message_number;
} else {
$low = ($page - 1) * $user_message_number;
$high = $page * $user_message_number;
}

$messages = mysql_query("SELECT * FROM messages WHERE recipient='$user_id' ORDER BY id DESC LIMIT $low, $high") or die(mysql_error());
while($pull_messages = mysql_fetch_array($messages)) {
// Displays content
}

 

That's all of the code that would directly effect the outcome... Any thoughts/comments/suggestions are greatly appreciated.

Link to comment
Share on other sites

MySQL LIMIT isnt used in a 'show record 5 upto record 10' way.

It is more of a 'starting from 5 show 5 records.'

 

Having said that, you only need to figure out what page number you are upto and find the starting record, your $high variable should be $user_message_number

 

$messages = mysql_query("SELECT * FROM messages WHERE recipient='$user_id' ORDER BY id DESC LIMIT $low, $user_message_number") or die(mysql_error());

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.