PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

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:
  #1  
Old August 30th, 2002, 01:47 AM
Scurvy Scurvy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Ormond Beach, FL USA
Posts: 26 Scurvy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
using a url to change display order?

Hello again all. I'm back with another query for the guru's. Not sure if this is php or html ? but here goes

I have my db output as such:

name | age | dob
bob | 14 | whatever
tom | 21 | whatever
etc.

I'd like to have 'name' and 'age' be links to show the same info but ordered by 'name' or 'age'.
Can this be done in the url as in:
www.mydomain.com/ages.php?ORDERBY=age

I tried several similar strings but nothing works. Just refreshes the current page.
Without making a separate php page with the different order by queries is this possible and if so, what's the proper syntax?

Thanks for any info
Scurvy

Reply With Quote
  #2  
Old August 30th, 2002, 02:13 AM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: using a url to change display order?

You could do something like this....

php Code:
Original - php Code
  1. <?
  2. if(!isset($_GET['ORDERBY']) {
  3.   /* set default ordering if nothing in url */
  4.   $orderby = 'name';
  5. } else {
  6.   /* make sure no bogus info is passed */
  7.   $valid = array('name','age');
  8.   if (in_array($_GET['ORDERBY'],$valid) {
  9.     $orderby = $_GET['ORDERBY'];
  10.   } else {
  11.     $orderby = 'name';
  12.   }
  13. }
  14. $query = "SELECT name,age,dob FROM yourtable ORDER BY $orderby";
  15.  
  16. /* now on to the rest of your code as normal. */
  17. ?>


Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > using a url to change display order?


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