This is a discussion on newbie question: results by page within the PHP Language forums, part of the PHP Programming Forums category; Hello, How do I make results that I select from my database on different pages based on length? For instance, ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hello,
How do I make results that I select from my database on different pages based on length? For instance, say I have over 50 records with more being added and I want it to display 10 records per page. How do I get that info to display only 10 at a time instead everything all in one page? Thanks in advance! |
|
|||
|
John wrote:
> How do I make results that I select from my database on different pages > based on length? > > For instance, say I have over 50 records with more being added and I want it > to display 10 records per page. How do I get that info to display only 10 at > a time instead everything all in one page? You're working with MySQL? Have a look at <http://www.mysql.com/doc/en/SELECT.html> and a very good look to LIMIT. Saludo Paul. |
|
|||
|
"John" <gt2243a@mail.gatech.edu> wrote in message
news:c2dabl$ap4$1@news-int.gatech.edu... > Hello, > > How do I make results that I select from my database on different pages > based on length? > > For instance, say I have over 50 records with more being added and I want it > to display 10 records per page. How do I get that info to display only 10 at > a time instead everything all in one page? > > Thanks in advance! > > > Put a LIMIT clause in your query. From the MySQL docs: http://www.mysql.com/doc/en/SELECT.html The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must be integer constants. With one argument, the value specifies the number of rows to return from the beginning of the result set. With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1): To be compatible with PostgreSQL MySQL also supports the syntax: LIMIT row_count OFFSET offset. mysql> SELECT * FROM table LIMIT 5,10; # Retrieve rows 6-15 To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter. This statement retrieves all rows from the 96th row to the last: mysql> SELECT * FROM table LIMIT 95,18446744073709551615; If one argument is given, it indicates the maximum number of rows to return: mysql> SELECT * FROM table LIMIT 5; # Retrieve first 5 rows |
|
|||
|
John wrote:
> For instance, say I have over 50 records with more being added and I want it > to display 10 records per page. How do I get that info to display only 10 at > a time instead everything all in one page? Use the LIMIT clause in your SQL query: SELECT col1, col2 FROM table WHERE col3='public' ORDER BY col1 LIMIT 10, 20 will return the 20th, 21st, ..., 29th record -- --= my mail box only accepts =-- --= Content-Type: text/plain =-- --= Size below 10001 bytes =-- |
|
|||
|
Take a look at http://www.tonymarston.co.uk/php-mysql/pagination.html
-- Tony Marston http://www.tonymarston.net "John" <gt2243a@mail.gatech.edu> wrote in message news:c2dabl$ap4$1@news-int.gatech.edu... > Hello, > > How do I make results that I select from my database on different pages > based on length? > > For instance, say I have over 50 records with more being added and I want it > to display 10 records per page. How do I get that info to display only 10 at > a time instead everything all in one page? > > Thanks in advance! > > |