|
Posted by Sandman on 09/08/05 21:34
In article <1126148269.374612.295050@g49g2000cwa.googlegroups.com>,
"yellow1912" <yellow1912@yahoo.com> wrote:
> Ok, lets say I have 1000 items in my database (mysql) and want to
> display X items per page. I learned to do it by querying with the LIMIT
> constrain (something like this
> http://www.snipe.net/content/view/12/35/). The problem is I cant sort
> using this algorithm (or maybe I just dont know how to do it). ORDER BY
> didnt do the trick for me :(.
> The only way I can think of is to pass all the item keys/names/anything
> I want to sort into an array, sort them there then pass the array
> between pages. But I really dont like this idea. I know there must be
> better way to do this, anyone can help a newbie?
You should use "order by" for this and let MySQL do the trick. Can't say why it
failed, but any given query could look like this:
select * from table order by date limit 25
For page navigation:
<?
if (!$_GET["start"]) $_GET["start"] = 0;
if (!$_GET["order"]) $_GET["order"] = 'date';
$sql = "select * from table order by $_GET[order] limit $_GET[start],25";
?>
--
Sandman[.net]
Navigation:
[Reply to this message]
|