Jump to content

ORDER BY - Table and listings


saeed_violinist

Recommended Posts

Dear friends,

 

I am not sure if my question is related to mysql!

 

the problem is I have a normal table to list users in database, and in first row of table ofcourse there is a listing like this:

 

Username | Full name | Join Date |....

 

now I want to make it somehow that by clicking on the, for example, full name, the table ordered by full name ( I mean A to Z), I know I can do it by making it to a hyperlink and adding somthing like "list.php?order=fullname", it will be listed as I want.

 

but the question is how can I make it somehow that if user click on the link first time, it ordered by ASC and next click order it by DESC, is it done by javascript or something?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/160759-order-by-table-and-listings/
Share on other sites

Well you sort of answered your own question there.

There are 2 ways to do it, depending on what you want/prefer.

 

1) Use a PHP query string to order the output at the backend, and then redisplay.

2) Use an internal client side javascript array , and onclick re-order it and redisplay the table.

 

You want to tell your script whether you are ordering ASC or DESC, regardless of which method above you choose.

i.e. list.php?order=fullname&direction=asc

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.