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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kevin7
Forum Commoner
Posts: 96
Joined: Fri May 21, 2004 6:54 am

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

Post 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~!!! :)
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
kevin7
Forum Commoner
Posts: 96
Joined: Fri May 21, 2004 6:54 am

Post 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..
Post Reply