newbie question: results by page

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, ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-06-2004
John
 
Posts: n/a
Default newbie question: results by page

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!


Reply With Quote
  #2 (permalink)  
Old 03-06-2004
Paul Wellner Bou
 
Posts: n/a
Default Re: newbie question: results by page

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.
Reply With Quote
  #3 (permalink)  
Old 03-06-2004
jn
 
Posts: n/a
Default Re: newbie question: results by page

"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


Reply With Quote
  #4 (permalink)  
Old 03-07-2004
Pedro Graca
 
Posts: n/a
Default Re: newbie question: results by page

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 =--
Reply With Quote
  #5 (permalink)  
Old 03-07-2004
Tony Marston
 
Posts: n/a
Default Re: newbie question: results by page

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!
>
>



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:34 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0