markvaughn2006 Posted January 29, 2010 Share Posted January 29, 2010 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!! Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted January 29, 2010 Share Posted January 29, 2010 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 Quote Link to comment Share on other sites More sharing options...
markvaughn2006 Posted January 29, 2010 Author Share Posted January 29, 2010 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!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.