|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Order by clause and different headings
ok...
Here's the thing i have a table, with 8 different fields username division _id sys_dba hq_dba div_dba active id this table is set up with a global order by clause "users.username" Now, this part i understand fully, and have the ability to make them asc or desc, but only based on the username. I have set up the headers for the table of these fields as links, and with that when a viewer clicks on say the link division_id all the information is then ordered by that field column. I'm sure it's easier then i'm thinking of it, but could someone please point me in the right way? Does it have something to do with putting an order by clause where the fields are now links? thanx |
|
#2
|
|||
|
|||
|
RE: Order by clause and different headings
You can put an ORDER BY clause into any SELECT query. For instance, if I wanted your table sorted by email, the query would be
Code:
"SELECT * FROM users ORDER BY email" Does that help? |
|
#3
|
|||
|
|||
|
RE: Order by clause and different headings
Yup and it already has one right, that sorts everything by the username...
what i want is to set it up so it sorts by what ever heading the user clicks on... here's the code tabels[] = "users" $fields[] = "username" $fields[] = "division_id" $fields[] = "div_dba" $fields[] = "email" $fields[] = "id" (i shortened it a bit) now see that query is set up with a global order by clause for the username to be the way all the info is sorted. Now, the headings have become linked: $link["username"] = 1; $link["division_id"] = 1; $link["div_dba"] = 1; $dont_link["email"] = 1; $link["id"] = 1; See? and i want those headings that have been linked, or colums if it sounds better, i want when a user clicks on one, say they click on division id, that the information in the table would then switch from being ordered by with the username into the division id. Maybe it's more complicated then i'm thinking, right now all it does is switch between asc/desc, no matter which one is clicked. |
|
#4
|
|||||
|
|||||
|
RE: Order by clause and different headings
OK, here goes... it can be broken down into three steps.
Step 1: Make the column heads links I'll assume the data is being output in an HTML table, and the field names are in the top row, perhaps in <TH> cells. So you're echo()ing or print()ing statements like this. You want that to be a link, to sort the table by division_id. So do like so. Do the same for every column heading which you want to be clickable. Step 2: Use a variable At the beginning of your script, see if there is a value for sortlist in the request. If there is, then that means someone clicked on one of the column heads. Do like so: php Code:
Step 3: Put ORDER BY clause in your query This is the easiest part. Just write your query like so: Do those three steps, and you're done. |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Order by clause and different headings |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|