Jump to content


Photo

sql case statement


  • Please log in to reply
3 replies to this topic

#1 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 24 October 2006 - 03:14 PM

Hi, i am drawing the names of cars out of my database. There are 6 different types of car and i want to put them in a specific order. I'm pretty sure i need to use a case statement to do this but i can't remember exactly how to do it as i need it, and when i google it i can't find anything that is similar to what i'm looking for.

Can someone please demonstrate one for me?

Thanks.

#2 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 24 October 2006 - 03:22 PM

<?php

$sql = "SELECT carname, make, model, color FROM cars ORDER BY carname ASC"; 

$result = mysql_query($sql, $conn);

?>


#3 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 24 October 2006 - 06:38 PM

Thats not what i mean at all.

I am drawing them by name only. The order is not alphabetical, it is a specific order set by me.

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 24 October 2006 - 06:50 PM

The order is not alphabetical, it is a specific order set by me.


Then you should create an orderby field in your database and order by that.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users