View Full Version : Creating dropdown from mySQL info?
mokimofiki
Aug 25th 2008, 8:10 am
The code below is supposed to display a dropdown option box with the information in the table series that has the information in the series column ... of course it is not working any help would be great thank you.
ALSO: my connection to the db is fine the problem is in the source below somewhere :)
<?php
$result = mysql_query("SELECT series FROM series");
print "<select name=series> \n";
print "<option></option>";
while($row = mysql_fetch_assoc($result))
{
print "<option value = $row[series]</option> \n";
}
print "</select> \n";
?>
jayshah
Aug 25th 2008, 8:21 am
Try replacing:
print "<option value = $row[series]</option> \n";
Withprint "<option value=\"{$row['series']}\">{$row['series']}</option> \n";
If that doesn't work, please paste the entire HTML output as sometimes MySQL Errors are within the <select>, so aren't displayed.
Jay
mokimofiki
Aug 25th 2008, 8:33 am
Okay I replaced my code with your suggestion above and the html output is:
<select name=series>
<option></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
</select>
Its also displaying the correct number of options they are just empty?!
if I just echo whats in the mySQL table it displays fine but trying to get it into the dropdown seems to be very irritating :)
jayshah
Aug 25th 2008, 8:37 am
Please add:var_dump($row); Under the your while($row = ...){ line, and paste that output.
Jay
mokimofiki
Aug 25th 2008, 8:44 am
Thank you that seems to have worked
I appriciate all of your help :)
jayshah
Aug 25th 2008, 8:45 am
Thank you that seems to have worked
I appriciate all of your help :)
Really? :D
It should just dump $row, not into a <option> or anything. Thanks for the rep. and let me know if you need anything :o
Jay
mokimofiki
Aug 25th 2008, 9:02 am
I added before the while($row ... so i assume somewhere else in my page row is used and never released. Np rep definatly deserved thank you again :)
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.