re:[PHP-DB] Splitting Product catalog

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

 



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


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

  Powered by Linux