RE: Splitting Product Catalogue Over Multiple Pages?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If you're trying to do paging, it's quite simple (there are tons of examples
out there, search google for paging php)

$sql = "select count(*) from table_name"

$number_of_records = mysql_query($sql);
$pointer=0;
$recs_per_page=20;

if($number_of_records > $recs_per_page) {
	// do a limit and keep the pointer
$sql = "select * from other_table limit $pointer,$recs_per_page";

$pointer += $recs_per_page;


This isn't complete by any means but the point should be clear. You limit
the query by "LIMIT starting_point,number_of_records_to_return" at the end
of the sql statement.

Don't worry about the values in the column, just the amount of records you
want to return



Gary Every
Sr. UNIX Administrator
Ingram Entertainment
(615) 287-4876
"Pay It Forward"
mailto:gary.every@ingramentertainment.com
http://accessingram.com


> -----Original Message-----
> From: Boa Constructor [mailto:mickel@ntlworld.com]
> Sent: Thursday, June 26, 2003 10:25 PM
> To: php-db@lists.php.net
> Subject:  Splitting Product Catalogue Over Multiple Pages?
> 
> 
> Greetings all, I'm not sure if this has been discussed 
> recently, I've read
> bits and pieces and I can't remember where I read everything 
> so if it has
> been brought up recently - sorry.
> 
> If I do an SQL (MySQL) query on the first example to get the 
> min and max IDs
> then I will get 1 and 6 respectively.  I will then be able to 
> loop from 1 to
> 6 and return all 6 products from the database.  If however I 
> wanted to split
> this in to two pages with 3 items in each page then using the 
> first example
> below I could grab the min ID and add 2 to it to make 3.  I 
> could not do
> this using the second example because if I grab the min ID I 
> would get 3, if
> I add 2 to it then I would get 5.  5 does not exit in this 
> table so that
> wouldn't work.  How in example 2 would I be able to split 
> this over two
> pages?
> 
> //example 1
> 
> ID   Product_Name
> 1      Hoover
> 2      Kettle
> 3      Fridge
> 4      Cooker
> 5      Food Mixer
> 6      TV
> 
> //example 2
> 
> ID   Product_Name
> 3     Fridge
> 4     Cooker
> 7     Microwave Oven
> 8     Freezer
> 9     DVD Player
> 10   Computer
> 
> 
> Any ideas?
> 
> Anything is much appreciated.
> 
> Graeme :)
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux