Michael, thank you so much for that code.  I think I could maybe get this
working properly.  I've got 2 categories and 4 products in each and I want
to split them in to 2 pages, 2 products on each.  So obviously I will have 2
links at the bottom "page 1 2......" etc   when I click the link "2" I will
need 2 tell the database to look up the 3rd and 4th record.  So would it be
possible to pass a parameter in the URL such as "&newpage=2" then multiply
it by 2 and use that as the maximum limit then take 1 away from that value
and use that as the minimum limit in the SQL query?

Basically:

2x2 = 4 (maximum limit)
4-1 = 3  (minimum limit)

Would this work?

Cheers,

Graeme :)

----- Original Message -----
From: "Michael Lewis" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, June 27, 2003 3:47 PM
Subject: [PHP-DB] re:[PHP-DB] Splitting Product catalog


> Graeme,
>
> Use a select string as in,
>
>     $sel="select * from product where price<100 order by price LIMIT
0,100";
>
> This would result in the query only returning the first 100 records. If
you
> want to page through them (back and next links). You would have to save
the
> current start point and the length would be the number of records you want
> to display. Take the following example (please) which selected records in
> groups of tens:
>
> session_start();
> $start=$_SESSION['start'];
> sel="select count(*) from product";
> $res=mysql_query($sel) or die(mysql_error());
> $r=mysql_fetch_array($res);
> $totalmsg=$r[0];
> if ($start>$totalmsg) {
>         $start=0;
>         $_SESSION['start']=0;
> }
> $res=mysql_query($sel) or die(mysql_error);
> $numtoprocess=10;
> $numselected=mysql_num_rows($res);
> if ($numselected<$numtoprocess) {
>     $numtoprocess=$numselected;
> }
> $sel="select * from product limit $start,$numtoprocess";
> for ($i=0;$i<$numtoprocess;$i++) {
>     process the record here
> }
> $start+=$i;
> $_SESSION['start']=$start;
>
> yada, yada, yada (put your back and next buttons here)
>
> The above code is stripped of most error checking etc., but it should give
> you a framework to get started.
>
> Michael Lewis
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to