Jump to content


Photo

Simple SQL Question


  • Please log in to reply
2 replies to this topic

#1 TennesseeGuy

TennesseeGuy
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 08 April 2006 - 08:13 AM

Is it possible to query your results, list them in ascending order but excluding one from the ascending order that neds to be added to the end? ie ordered after query: A,B,C,D,E,G,H,I,J,K,F

#2 westnyorai

westnyorai
  • New Members
  • Pip
  • Newbie
  • 4 posts
  • LocationWY

Posted 09 April 2006 - 12:11 AM

[!--quoteo(post=362749:date=Apr 8 2006, 03:13 AM:name=TennesseeGuy)--][div class=\'quotetop\']QUOTE(TennesseeGuy @ Apr 8 2006, 03:13 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Is it possible to query your results, list them in ascending order but excluding one from the ascending order that neds to be added to the end? ie ordered after query: A,B,C,D,E,G,H,I,J,K,F
[/quote]

$query="SELECT * FROM $table ORDER BY $fieldheader";
mysql_query($query);

that will arrange the data by field type. As far as placing only one at the end you would have to probably add a WHERE statement and have it list all except the one you wanted placed last. Then have it list the last one afterwards with another WHERE statement.



#3 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 09 April 2006 - 06:45 PM

Actually, you can do this in a single query:

"SELECT * FROM $table ORDER BY FIELD( $fieldheader, 'F' ), $fieldheader"

Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users