new pages....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
AndrewBacca
Forum Commoner
Posts: 62
Joined: Thu Jan 30, 2003 10:03 am
Location: Isle of Wight, UK

new pages....

Post by AndrewBacca »

im designing this site for a friend of mine who sells motorbike gear and he wants to display all his products that he sells on the site, but ive noticed that he has alot of stuff.

What i thought about doing was have about 25 iteams per page, so it loads 25 iteams and continues on another page "page1, page2, page3..." type thing.

I have all the data stored in a MYSQL database, any ideas on how i can do this.

if you need more info, just ask :D

cheers
Andrew
User avatar
delorian
Forum Contributor
Posts: 223
Joined: Sun May 04, 2003 5:20 pm
Location: Olsztyn, Poland

Post by delorian »

The simplest solution is to count all the products. Divide the returned number by 25 to know how many page links you'll have to create. Then the links could look something like this:

Code: Select all

list.php?start=0&stop=25 // for page1
list.php?start=26&stop=50 // for page2 
// etc.
Then you must show the products from start number to stop number only. I think that will work.

Another thing to do is to put that start-stop numbers in database query. You must have the id column so you can use this to get the right records. But if you remove one of the product, then the id will also be removed so on one page you could see 24 not 25 products. :P
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

use the mysql LIMIT

which provides that you have some index-column, e.g. "id"

SELECT * FROM articles ORDER BY ID ASC LIMIT 0,24

which pulls the first 25 records from your DB-table. To pull the next 25 you would simply change LIMIT 25,49 and so on.

The actual numbers in your index-column "id" don't matter, they are only there to provide an index-framework.
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

patrikG wrote:which pulls the first 25 records from your DB-table. To pull the next 25 you would simply change LIMIT 25,49 and so on.
Nope, LIMIT 25,49 will give you 49 records starting with the 25th.

To pull the next 25 records out of your database use LIMIT 25,25.

Off corse you can use a varable for the starting record.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

^
|
|
right

<--- wrong
Post Reply