Page 1 of 1

IS there somthing wrong with my switch statement??

Posted: Sun Jan 18, 2009 11:29 am
by cyandi_man
Hi fellas...i took some advice in using a switch statement to accomplish what i wanted.
I basically just want a specific list to be displayed depending on the office type and location chosen from a dropdown list. Only now the listing that is displayed does not seem to coinside with the
selected choices from the drop-down. eg. if choosing a chiropractor from toronto, i get an optometrist showing up in the list! I checked the switch code and it seems to be correct!? help please!

Code: Select all

 
--database statements--
  $db = mysql_select_db($database,$connection)
       or die ("Couldn't select database");
 
if ($city=="-Any City-" && $industry=="-Any Discipline-") {
    $i==0;
}
 elseif ($city!="-Any City-" && $industry!="-Any Discipline-") {
    $i==1;
} 
elseif ($city=="-Any City-" && $industry!="-Any Discipline-") {
    $i==2;
} 
elseif($industry=="-Any Discipline-" && $city !="-Any City-") {
   $i==3;
}
 
switch ($i) {
    case 0:
    $query = "SELECT * FROM Proffesional_list";
    break;
    case 1:
    $query = "SELECT * FROM Proffesional_list WHERE industry='$industry' AND city='$city'"; 
    break;
    case 2:
     $query = "SELECT * FROM Proffesional_list WHERE industry='$industry'";
     break;
    case 3:
    $query = "SELECT * FROM Proffesional_list WHERE city='$city'";
    break;
}
 
 
$result= mysql_query($query)
or DIE("unable to retrieve database info");
--echo statements pas here--
I do get listings that show up - but not the proper selections!

Re: IS there somthing wrong with my switch statement??

Posted: Sun Jan 18, 2009 11:31 am
by Burrito
how is $i being set?

try echoing out your $query to see if it's what you intend for it to be.