Page 1 of 1

[SOLVED] arr... page numbering...

Posted: Thu Jun 24, 2004 10:58 pm
by kevin7
arr... i'm getting mad...

i've 30 records in a table... and i wanna to display it based on the number of records in the table... each time 10 records..

the following is my code... is a MESS...!

Code: Select all

<?
//retrieve from table to find how many record inside the table
//and then divide it with 10 to find the total of pages

$num = mysql_query("SELECT ord_id FROM `order` ORDER BY ord_id DESC");
$numrow = mysql_num_rows($num);
$numrow = $numrow/10;


// if the number divide by 10 return 4.1, it will become 5
//so, there will be total of 5 pages

ceil($numrow); 


//this is where generate the number of pages required and the link with query strings

$x=10;
$z=0;
for($i=1;$i<=$numrow;$i++) {

echo "<A href="browse2.php?low=$z&high=$x">$i</A>";

$z+=10;
$x+=10;
}

?>
i'm hv two query string called low and high... which pass to another page to display... the code is like below...

Code: Select all

$high=$_REQUEST['high'];
$low=$_REQUEST['low'];

$order = mysql_query("SELECT ord_id FROM `order` ORDER BY ord_id DESC LIMIT $low, $high", $db);
so, it will display the record based on the LIMIT... this is my thought... this code can run... but the total of records was incorrect...

do u hv any idea? or u know how to code it? please help me...

thank you~!!! :)

Posted: Thu Jun 24, 2004 11:16 pm
by Weirdan
you misunderstand the meaning of LIMIT parameters:
MySQL manual wrote: 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.

Posted: Thu Jun 24, 2004 11:31 pm
by John Cartwright
$order = mysql_query("SELECT ord_id FROM `order` ORDER BY ord_id DESC LIMIT $low, $high", $db);

should be

Code: Select all

<?php
$order = mysql_query("SELECT ord_id FROM `order` ORDER BY ord_id DESC WHERE ($i>$low && $i < $high)", $db) or die(mysql_error()); 
?>
pretty sure you get syntax error but jus givin u an example on how to do it

Posted: Fri Jun 25, 2004 1:17 am
by kevin7
Weirdan wrote:you misunderstand the meaning of LIMIT parameters:
MySQL manual wrote: 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.

ooo~ thank for correct me! i thought it was first and last..~ lol..