Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
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  
Old March 25th, 2003, 08:19 PM
myraleen myraleen is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Ottawa, Ontario, Canada
Posts: 123 myraleen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to myraleen Send a message via AIM to myraleen
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
email
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

Reply With Quote
  #2  
Old March 25th, 2003, 08:28 PM
SeanGleeson SeanGleeson is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Wichita, Kansas, USA
Posts: 92 SeanGleeson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to SeanGleeson Send a message via Yahoo to SeanGleeson
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?

Reply With Quote
  #3  
Old March 25th, 2003, 08:36 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
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.

Reply With Quote
  #4  
Old March 25th, 2003, 09:08 PM
SeanGleeson SeanGleeson is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Wichita, Kansas, USA
Posts: 92 SeanGleeson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to SeanGleeson Send a message via Yahoo to SeanGleeson
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.
php Code:
Original - php Code
  1.  
  2. <?php
  3. echo "<TH>Division ID</TH>n";
  4. ?>

You want that to be a link, to sort the table by division_id. So do like so.
php Code:
Original - php Code
  1.  
  2. <?php
  3. echo "<TH><A HREF="".$_SERVER['PHP_SELF']."?sortlist=division_id">Division ID</A></TH>n";
  4. ?>

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:
Original - php Code
  1.  
  2. <?php
  3. $SortListBy = "username";
  4. if ($_REQUEST['sortlist']) {
  5. $SortListBy = $_REQUEST['sortlist'];
  6. }
  7. ?>


Step 3: Put ORDER BY clause in your query
This is the easiest part. Just write your query like so:
php Code:
Original - php Code
  1.  
  2. <?php
  3. $query = "SELECT * FROM users ORDER BY ".$SortListBy;
  4. ?>

Do those three steps, and you're done.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Order by clause and different headings


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway