reel_biggy_fish Posted September 9, 2010 Share Posted September 9, 2010 i have a dropdown menu that displays the options i have in a database. i have this all working in mysqli as i didnt write this part on another website. but i am struggling to convert it back to mysql. the original code is: $query = "SELECT gallery_type_id, gallery_type_desc FROM gallery_type ORDER BY gallery_type_id"; /* run the query */ $result = $dbLink->query($query); /* load the query's results into an array */ $i=1; while($row=$result->fetch_assoc()){ $galleryTypes[$i] = $row; $i++; } $num_results = $result->num_rows; <select name="gallery_type" id="gallery_type"> <option>Please Select an Album <?php for($i = 1; $i < $num_results+1; $i++) { echo "<option value=\"" . $galleryTypes[$i]['gallery_type_id'] . "\">"; echo $galleryTypes[$i]['gallery_type_desc']; echo "</option>\n"; } ?> the code i have got so far: $query1 = "SELECT id, question FROM securtiyq ORDER BY id"; /* run the query */ $result= mysql_query($query1); $row = mysql_fetch_array($result); /* load the query's results into an array */ $i=1; while ($row = mysql_fetch_assoc($result)) { $galleryTypes[$i] = $row; $i++; } $num_results = mysql_num_rows($result); <select name="gallery_type" id="gallery_type"> <option>Please Select A Security Question <?php for($i = 1; $i < $num_results+1; $i++) { echo "<option value=\"" . $galleryTypes[$i]['id'] . "\">"; echo $galleryTypes[$i]['question']; echo "</option>\n"; } ?> </option> </select> the only problem is nothing from the database is displayed in the dropdown box. could someone point out where im going wrong thanks in advance Link to comment https://forums.phpfreaks.com/topic/212990-load-data-from-db-into-a-option-box/ Share on other sites More sharing options...
systemick Posted September 9, 2010 Share Posted September 9, 2010 Put a closing </option> tag after 'Please Select A Security Question' and remove the last </option> tag and see if that works Link to comment https://forums.phpfreaks.com/topic/212990-load-data-from-db-into-a-option-box/#findComment-1109295 Share on other sites More sharing options...
reel_biggy_fish Posted September 9, 2010 Author Share Posted September 9, 2010 no sorry that didnt work unfortunatly Link to comment https://forums.phpfreaks.com/topic/212990-load-data-from-db-into-a-option-box/#findComment-1109296 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.