Page 1 of 1
NEXT 25 records?
Posted: Tue Jan 28, 2003 8:54 pm
by JavaScript
how can i display the next 25 records on my mysql table?
The situation is that i need to query and show the table data 25 records per page but don't know how to stop displaying them 25 each per page and continue to next page, next page...
Posted: Tue Jan 28, 2003 9:41 pm
by kcomer
Code: Select all
SELECT * FROM myCars WHERE color = 'red' LIMIT 26,50
Make LIMIT 0,25 or whatever you are looking for. First number is the start, last is the end.
Keith
Thanks bro!
Posted: Wed Jan 29, 2003 1:53 am
by JavaScript
But... if using that code, what will happen if we go over our records limit?
For example we have 63 records (and it will increase [i'm coding a news script])
If we limit 0,25 - 26, 50 - 51,76 <<<< We have 63 for now
What will happen?
Posted: Wed Jan 29, 2003 2:19 am
by twigletmac
It will return as many records as it can up to the limit you set but if there are less records than the limit that is not a problem - you're final page will be a bit shorter but there'll be no error caused or anything.
Mac
One more...
Posted: Wed Jan 29, 2003 2:50 am
by JavaScript
One more issue
How can we know the limit?
In our example, we consider the table contains 63 records but in our productive environment, we don't know where is the stop of our records, do we?
So how can we know where to stop generating a NEXT link as it will put our visitor to no where.
Thanks for all your great helps
Posted: Wed Jan 29, 2003 7:41 am
by Stoker
..without much error control...
Code: Select all
<?php
$rows_per_page = 25;
If (empty($_GET['offset']) || !is_numeric($_GET['offset'])) $offset = 0;
else $offset = (int) $_GET['offset'];
$db = mysql_connect_db('host','user','pass');
mysql_select_db('mydb',$db);
$r = mysql_query("SELECT count(*) FROM mytable WHERE blah='duh' AND hihaa='beer'",$db);
list($rowcount) = mysql_fetch_row($r);
# Create something to divide the rowcount with $rows_per_page
# and display a bunch of pagelinks with ?offset=nnn etc
$r = mysql_query("SELECT col1,col2,col3 FROM mytable WHERE blah='duh' AND hihaa='beer'
ORDER BY something,col2 LIMIT ".$offset.','.$rows_per_page,$db);
# Fetch the rows and show them etc...
?>
Beautiful!
Posted: Wed Jan 29, 2003 8:03 am
by JavaScript
That's what i'm looking for!
I will be back here to show all you guy the news script (GPL)
Thanks
