Jump to content

Recommended Posts

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 co-inside with the

selected choices from the drop-down.  ex. 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!

 

 

thanks for the help!

only now it seems that there is something wrong with my switch statement!

--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!

  $i==3;

 

you're using the comparison operator, not to set it

 

$i = 3;

 

is correct

 

Thanks - i corrected that .  however it seems that i am not getting the values for industry and city from my form page when i choose "-any city-" and/or "-any discipline-"

 

Im new to coding...so - im not sure if i coded my drop down menu correctly.

i coded it as follows.

 

<?php 
-database connection code-


  $connection = mysql_connect($host,$user,$password)
       or die ("couldn't connect to server");
  $db = mysql_select_db($database,$connection)
       or die ("Couldn't select database");


  $query = "SELECT DISTINCT industry FROM Proffesional_list ORDER BY industry";
  $result = mysql_query($query)
       or die ("Couldn't execute query.");
        
  $query2 = "SELECT DISTINCT city FROM Proffesional_list ORDER BY city";
  $result2 = mysql_query($query2)
       or die ("Couldn't execute query.");
   
   $anycity ="-Any City-";
   $anyplace ="-Any Discipline-";

  /* create form containing selection list */
  echo "<form action='code/memberdisplaylist.php' name='list1_form' method='POST'>
        <select name='industry'>\n";
echo "<option value='$industry'>$anyplace</option>\n"; 
  while ($row = mysql_fetch_array($result))
  {
     extract($row);
     echo "<option value='$industry'>$industry\n";
  }
  echo "</select>\n";
  ?>
  
//location dropdown menu
<p> </p>
<span class="subheading">Location</span> <br/><?php
  /* create form containing selection list */
  echo "<form action='code/memberdisplaylist.php' name='list1_form' method='POST'>
        <select name='city'>\n";
echo "<option value='$city'>$anycity</option>\n";
  while ($row2 = mysql_fetch_array($result2))
  {
     extract($row2);
     echo "<option value='$city'>$city\n";
  }
  echo "</select>\n";
  ?>
<p> </p>
  <?php
?>

 

Is there anything wrong with my php coding? 

 

(edited to add


tags)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.