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...
NEXT 25 records?
Moderator: General Moderators
Code: Select all
SELECT * FROM myCars WHERE color = 'red' LIMIT 26,50Keith
-
JavaScript
- Forum Newbie
- Posts: 7
- Joined: Tue Jan 28, 2003 8:54 pm
Thanks bro!
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?
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?
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
-
JavaScript
- Forum Newbie
- Posts: 7
- Joined: Tue Jan 28, 2003 8:54 pm
One more...
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
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
..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...
?>-
JavaScript
- Forum Newbie
- Posts: 7
- Joined: Tue Jan 28, 2003 8:54 pm
Beautiful!
That's what i'm looking for!
I will be back here to show all you guy the news script (GPL)
Thanks