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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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