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
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

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.