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
https://forums.phpfreaks.com/topic/248606-help-debuging-limit/
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
https://forums.phpfreaks.com/topic/248606-help-debuging-limit/#findComment-1276689
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.