RE: [PHP] Prev/Next
| From: | Samantha Savvakis | Date: | Mon, 16 Oct 2000 06:16:28 +0000 |
| Subject: | RE: [PHP] Prev/Next | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-20305@lists.php.net to get a copy of this message | ||
This is all in your SQL statement.
There is a command in SQL called "LIMIT". It goes:
LIMIT startvalue, no. of results.
eg. LIMIT 10, 50 - start at result 10 and give me 50 results.
With my website, I only want to display 10 results at one time. The search
might return 70 results. Initially, I have this sql statement:
"select * from table LIMIT 0,10" - this will limit the query to the first 10
items that are returned. The "NEXT" button on the first page will then know
to start the next LIMIT at 10 and go to 20. ie. "select * from table LIMIT
10, 10"
So on the next page, I will see PREV/NEXT buttons.
The PREV button will know that we have started at 10 and want to go back 10.
So we subtract from the start value the number we want to go back ie. LIMIT
0, 10
NEXT button will know we started at "10" and this time we want to add "10" -
ie. LIMIT 20, 10
Always remember what the start value is on your page.
I don't know if I've explained myself very well, but this is how you do it.
> -----Original Message-----
> From: Website4S@aol.com [mailto:Website4S@aol.com]
> Sent: Monday, 16 October 2000 15:56
> 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
>