cyandi_man Posted January 17, 2009 Share Posted January 17, 2009 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! --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: $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! Quote Link to comment Share on other sites More sharing options...
btherl Posted January 17, 2009 Share Posted January 17, 2009 Each option tag should be closed. To set the default, you mark one of them as "selected" like this: echo "<option value='$industry' selected>-Any Dicipline-</option>" Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted January 17, 2009 Share Posted January 17, 2009 edit: what he said, but if you enabled E_ALL you'd see there was an undefined variable error for $industry before the while loop. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.