I want to display my records 20 at a time.
If I use the query without ORDER BY, it works, but if I try ordering them , I have problems. This seems to make sense to me, but I really need to order them. How can I do this ?
TIA pat
$order_by="typ_art, date_art desc";
$display = 20;
$lower_limit = 1;
$higher_limit=$display ;
$query = "SELECT titre, id_art , typ_art, expire, date_art FROM info limit $lower_limit , $higher_limit ORDER BY $order_by ";
$result = @mysql_query ($query); // Run the query.
$bg = '#eeeeee'; // Set the background color.
$param = $_GET['type_call']; // get the type of call , S=supprimer, M=modifier
while ($row = mysql_fetch_assoc($result)) :
. . .
endwhile;
First, the ‘order by’ value should be explicit – i.e. if you want ‘typ_art’ ascending, write ASC instead of leaving it blank.
I’d recommend formatting the query using indentation (like below) and comments for simple lines.
The ‘while’ syntax is much easier to read using { } instead of ‘endwhile’.
$order_by = "typ_art, date_art desc";
$display = 20;
$lower_limit = 1;
$higher_limit = $display;
$query = "SELECT titre, id_art , typ_art, expire, date_art
FROM info
LIMIT $lower_limit, $higher_limit
ORDER BY $order_by";
$result = @mysql_query($query);
$bg = '#eeeeee';
$param = $_GET['type_call'];
while ($row = mysql_fetch_assoc($result))
{
}
Now, to your main problem. The limit part is wrong. The first parameter is how many you want returned (say 20), and the second is how many rows to offset by (say you are on page 3, then offset would be 40, because you want to see rows 41-60).