IF ELSE LOOP - Different situation...!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cyandi_man
Forum Newbie
Posts: 12
Joined: Sun Nov 02, 2008 10:47 am

IF ELSE LOOP - Different situation...!

Post by cyandi_man »

Hi Guys - id like to thank you all for helping me thus far. I was wondering if anybody can tell me if there is anything wrong with the following loop. What it is is a directory listing that you can choose the location and service from dropdown menus. then the next page will display a list of locations based on your pick. im not sure.. but it seems like the default selections (it is a dropdown menu) are not returning a value. Please help!

Code: Select all

 
--previous code--
  $db = mysql_select_db($database,$connection)
       or die ("Couldn't select database");
 
if ($industry=="-Any Dicipline-" && $city !="-Any City-"){
$query = "SELECT * FROM Proffesional_list WHERE city='$city'";
}
else if ($city=="-Any City-" && $industry!="-Any Dicipline-"){
$query = "SELECT * FROM Proffesional_list WHERE industry='$industry'";
}
else if ($city=="-Any City-" && $industry=="-Any Dicipline-"){
$query = "SELECT * FROM Proffesional_list";
}
else if ($city!="-Any City-" && $industry!="-Any Dicipline-"){
$query = "SELECT * FROM Proffesional_list WHERE industry='$industry' AND city='$city'";
}
 
$result= mysql_query($query)
or DIE("unable to retrieve database info");
rest of the code and echo statements...
 
As you can see, my data is on the Proffesional_list (I KNOW I SPELLED IT WRONG)
only when i choose an actual item and location - the list is displayed - but when i choose one or the other or none at all - i get a blank listing.

The page with the dropdown menu precedes the page with the above code...
The dropdown menu in question is coded in php like so:

Code: Select all

$query2 = "SELECT DISTINCT city FROM Proffesional_list ORDER BY city";
  $result2 = mysql_query($query2)
       or die ("Couldn't execute query.");
 
  /* create form containing selection list */
  echo "<form action='code/memberdisplaylist.php' name='list1_form'>
        <select name='industry'>\n";
echo "<option value='$industry'>-Any Dicipline-\n";//<--this should be the default value
  while ($row = mysql_fetch_array($result))
  {
     extract($row);
     echo "<option value='$industry'>$industry\n";
  }
  echo "</select>\n";
  ?>
Is the default &industry value coded correctly?
The items in the industry dropdown are pulled dynamically from the database - except for the default value.
Please help! Thanks in advance!
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: IF ELSE LOOP - Different situation...!

Post by it2051229 »

but it seems like the default selections (it is a dropdown menu) are not returning a value
you mean when the page loads, the selected default choice from the drop down does not output something? or something else... because if it does,
you might want to put an "else" on your if-elseif statements. And put a default value for the $industry variable... when the page loads, it does not display anything since $industry is empty (same with $city)
Post Reply