pagination with mysql_query, for certain results

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
soianyc
Forum Commoner
Posts: 61
Joined: Wed Mar 30, 2005 2:48 pm
Location: NY

pagination with mysql_query, for certain results

Post by soianyc »

I have a pagination script working good but i recently encountered a problem. Im making a database for garments and i have the garments split up into Coats, Jackets, Strollers etc.... I set up a query

Code: Select all

// Define the number of results per page
$max_results = 6;

// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);

// Perform MySQL query on only the current page number's results
$sql = mysql_query("SELECT * FROM garment WHERE tog='coat' LIMIT $from, $max_results");
I got the script online and taylored it to my needs. I only want to show 6 items per page and everything is going great. I currently have 7 items in my database. 5 are coats, and 2 are jackets. Whats happening is the next and previous paginated links are showing up on all the pages. I realized that the query is working correctly and doing what i asked it to do, show 6 items and then go to the next page, however i want to make it so it shows 6 jackets and go to the next page, not show 2 jackets and go to the next page. I dont want to make a different table for each type of garment. How can i fix the query to make it work the way i want to.

Thanks for all your replys

-soia
User avatar
soianyc
Forum Commoner
Posts: 61
Joined: Wed Mar 30, 2005 2:48 pm
Location: NY

Post by soianyc »

I think i figured it out...Just testing out my results first before i get excited.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

glad we could be of assistance :lol:
User avatar
soianyc
Forum Commoner
Posts: 61
Joined: Wed Mar 30, 2005 2:48 pm
Location: NY

Post by soianyc »

yep it werks, thanx for the help
Post Reply