Forum Moderators: coopster

Message Too Old, No Replies

displaying a certain number of objects

         

daneosporin

2:27 am on Jun 10, 2005 (gmt 0)

10+ Year Member



If I have basic code something like this

$result = mysql_query("SELECT * FROM celebrities");
while ( $row = mysql_fetch_array($result) ) {
echo($row["url"]);
}

If I only want to display the first 25 results and then 26-50 somewhere else. What is the code to only display a certain section of the results so I can do this?

mcibor

6:35 am on Jun 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



LIMIT offset, how_many:

to display first 25:

$result = mysql_query("SELECT * FROM celebrities LIMIT 0, 25");
while ( $row = mysql_fetch_array($result) ) {
echo($row["url"]);
}

//to display 26-50:

$result = mysql_query("SELECT * FROM celebrities LIMIT 25, 25");
while ( $row = mysql_fetch_array($result) ) {
echo($row["url"]);
}

0 is first, so the 25th is row[24].
Best regards
Michal Cibor

daneosporin

4:26 pm on Jun 10, 2005 (gmt 0)

10+ Year Member



thanks mcibor! that worked perfect.