Jump to content

LIMIT $start, 10... how to pass last value queried into next page with GET??


markvaughn2006

Recommended Posts

Ok I know how to display the first or last 10 results of  a query...

 

$result = mysql_query("SELECT * FROM messages ORDER BY timemsg DESC LIMIT 10");

 

In a perfect world all the rows ID's would be in perfect order (i.e.- 10,9,8,7,6,5,4,3,2,1), so to display messages 30 to 40 I would just do LIMIT 30,10

but because of certain unforseen situations the actual results will end up being more like-

457

455

454

453

449

448

447

419

418

410

 

So I can display the last 10 results in descending order but then to show the "previous 10" results (using the above numbers for an example), I'm thinking I need to somehow

capture the last result in this query (410) so when you hit "previous 10" link it passes it through GET to the next page and the next page will use something like LIMIT $start,10

to display the 10 results with before "410" and so on. Any idea how to do this, I don't think it should be that hard, just can't figure it out. Sorry, if this is in wrong thread,

feel free to move to MYSQL board if it belongs there.. Thanks for any help!!

Link to comment
Share on other sites

here's a simplified version of the pagination I use.

$resultset=1;   // set this to the resultset you want
$perpage=10; 
$sql="select count(*) as count from table"; 
$result=$mdb2->query($sql); 
while($row=$result->fetchRow(MDB2_FETCHMODE_ASSOC))
{
$total=$row['count']; 
}
$total=ceil($total/$perpage) // total number of resultsets 
if($resultset > $total) { 
  $resultset=$total; 
}
if($resultset< 1) {
  $resultset=$total;
} 
$resultset=($resultset-1)*$perpage; 
$sql="select * from table limit $resultset,$perpage"; 
// get your results here 

Link to comment
Share on other sites

Thanks for the help! but would there be any way to just capture the last result in  a variable? Like if the results were: (122,121,119,118,115,110,109,107,106,104) Capture 104 into a variable and then on the next page just use ORDER BY timemsg DESC LIMIT 104,10 to show the next 10 results with a lower value than 104?? Thanks again!!

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.