Jump to content

order by


vang163

Recommended Posts

hi,

i've a table with 100 records.

i displayed the data into 10 records per page, therefore i've 10 pages of data.

 

using this query - "select * from table order by $column $direction limit $set_limit $limit_size"

where $column is the table column name

$direction - asc or desc

 

Assuming i'm at page 1, I can view the display data (1,2,3,4..10) in ascending order by default. But when i want to display the data in descending order for page 1, I'm getting descending order data from page 10.

 

I want to be able to see the page 1 data in ascending and in descending order. This applies to all other pages. (2,3,4...10)

Can someone show me how this can be done, thanks.

Link to comment
Share on other sites

When you order by DESC you have to select the last 10 rows, rather than the first 10.

 

I'm not sure if there's a quick way to do this with pure-SQL, but you could simply dump the ASC results into an array, and use array_reverse() if you wanted to display them in reverse order.

Link to comment
Share on other sites

hi,

i have no idea how to dump the ASC results into an array, can you show me how?

my initial idea was below but it does not work.

$sql = "select * from table";

$result = mysql_query($sql);

$asc = mysql_fetch_assoc($result);

$reverse_result = array_reverse($asc);

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.