Jump to content

load data from db into a option box


reel_biggy_fish

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.