[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-general
Subject:    Re: [PHP] limit contral
From:       Ernest E Vogelsinger <ernest () vogelsinger ! at>
Date:       2003-02-19 12:43:50
[Download RAW message or body]

At 13:11 19.02.2003, James Shergold said:
--------------------[snip]--------------------
>I'm making a script that pulls property (house) from a mysql
>database in categories e.g. there cat1, cat2 ect and in each
>category I only want to show 10 properties a time then click
>next to show the next 10 properties in that catorgy.
--------------------[snip]-------------------- 

Limiting the SQL result set brings you half the way there, as Jono already
pointed out:
    SELECT foo FROM bar ORDER by blah LIMIT 10

For paging, you might additionally tell the database where to start by
adding the OFFSET parameter:
    SELECT foo FROM bar ORDER by blah OFFSET 0 LIMIT 10
    SELECT foo FROM bar ORDER by blah OFFSET 10 LIMIT 10
    SELECT foo FROM bar ORDER by blah OFFSET 20 LIMIT 10

Note: This syntax is for PostgreSQL; MySQL also allows a slightly different
syntax:
    SELECT foo FROM bar ORDER by blah LIMIT 0,10
    SELECT foo FROM bar ORDER by blah LIMIT 10,10
    SELECT foo FROM bar ORDER by blah LIMIT 20,10

 From the MySQL manual (http://www.mysql.com/doc/en/SELECT.html):
SELECT [STRAIGHT_JOIN]
    ...
      [LIMIT [offset,] rows | rows OFFSET offset]

HTH,

-- 
   >O     Ernest E. Vogelsinger
   (\)    ICQ #13394035
    ^     http://www.vogelsinger.at/



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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic