PHP - Previous and Next Links - Starting Off with $start
(Page 3 of 5 )
Ok, so now we now what we are going to use to obtain the proper rows from the database. The question is, how do we know what to limit it by? Simple, we will pass a variable called $start from page to page. Now, let's start putting a little PHP code down.
<?php $query = "SELECT * FROM table LIMIT " . $start . ", 10"; ?> |
Ok, that's what our query is going to look like. Simple as that. This will select 10 rows from the table starting at whatever position $start is equal to.
When you are handing out your url, you don't want to give someone this: http://myserver.com/?start=0. That's just plain ugly. So, we need to assign an initial value to $start if it doesn't have one.
<?php if(!isset($start)) $start = 0; ?> |
Easy! Now, when someone hits our page, $start will be set to 0 (zero).
Next: Building the Previous and Next Links >>
More Database Articles Articles
More By Matt Wade
|
| · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | | |
|