RE: [PHP] Prev/Next
| From: | Maxim Maletsky | Date: | Mon, 16 Oct 2000 08:57:58 +0000 |
| Subject: | RE: [PHP] Prev/Next | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-20314@lists.php.net to get a copy of this message | ||
this might be of some help to you:
(by query I call the SQL statement)
step 1):
compose the query as you need so the query ($query) is now exactly
what you need to pull the data out (forget about limiting for now)
step 2):
connect to the database with your '$query' and count rows there.
Assign $num to the amount of rows.
step 3):
do something like this:
$limit = 7; // the amount of items to show on a page.
if(!$view) $view = 0; // I call the variable passed via GET
"view", and when it is not set, the default is '0'.
$limit_low = $view; // select the lowest value;
$limit_high = $view+$limit; // select the highest value;
$query .=" LIMIT $limit_low,$limit"; this adds to your $query. It
is still the same one as yours above but with the needed limitation on rows.
Now, process you script, pull the data out, whatever..........
step 4):
echo '<CENTER>';
if($limit_low >= $limit) applies only when the lowest limit
is higher or equal to the limit itself. (in other words we skipped
something)
{
echo '<A
HREF="'.$SCRIPT_NAME.'?view='.($limit_low-$limit).'">';
echo '<< Previous </a>';
}
echo ' ';
if($num > ($view+$limit)) applies when the total amount of
rows is still higher then the current count plus the limit of the next page.
{
echo '<a
href="'.$SCRIPT_NAME.'?view='.$limit_high.'">Next
>></a>';
}
echo '</CENTER>';
step 5):
Say thanks if it works for you and it's exactly what you need...
:-))
Cheers man!
-----Original Message-----
From: Website4S@aol.com [mailto:Website4S@aol.com]
Sent: Monday, October 16, 2000 2:56 PM
To: php-general@lists.php.net
Subject: [PHP] Prev/Next
Hi,
I have been searching threads and web sites for help with setting a display
limit and prev/next buttons but I am getting no where. The code I have found
I can`t get to work :/ Does anyone on the list have any suggestions for
adding a limit of 20 results per page and adding the prev/next buttons to
the
bottom for the following code ?
<TABLE BORDER="1"
WIDTH="2000"><tr><TH>Delete_User</TH></TR>
<?php
$host="localhost";
$user="";
$passwd="";
$dbase="";
$Selstmt = "SELECT * FROM Member order by Surname";
$dbh=mysql_connect($host, $user, $passwd);
$query=mysql_db_query($dbase, $Selstmt);
$num_rows=mysql_num_rows($query);
for ($i=0; $i<$num_rows; $i++)
{
mysql_data_seek($query, $i);
$array=mysql_fetch_array($query);
printf("<tr><td>%s</td><td>%s</td></tr>",
$array["Surname"]);
}
mysql_close();
?>
</TABLE>
Thanks in advance for any help.
Ade
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net