Jump to content

Insert select options into this code


daveyah2002

Recommended Posts

Hi,

 

I'm really at a loss here.

 

I have queried a table to get an option list, which returns what I expect but I need to then add it to some current code instead of the fixed option list presented.

The syntax is beyond me.

 

 

Please see attached.

Any pointers would be great.

 

 

 

 

OptionList.txt

Link to comment
https://forums.phpfreaks.com/topic/292412-insert-select-options-into-this-code/
Share on other sites

If I'm understanding you:

 

 

<select id="gallery" name="gallery" required>
<?php
while($option = mysqli_fetch_assoc($query))
{ 
   echo "<option value='{$option['gallery']}'>{$option['gallery']}</option>";
}
?>
</select>

There is nothing wrong with the code you posted.  Do you mean you want to save the output to the $photo_form variable instead of outputting it straight away?

 

You can change lines 13 - 18 to

$photo_form .=   $options;

Then define the options into the $options variable when you process your query results. Example

$sql = "SELECT DISTINCT gallery FROM photos WHERE user='$u'";
$query = mysqli_query($db_conx, $sql);
$options = '';
// process query. Define options into variable
while($option = $query->fetch_object())
{
	$options .= '<option>' . $option->gallery . '</option>';
}

.

 

Or just replace lines 13 to 18 with the following

// concatenate each option to $photo_form
while($option = $query->fetch_object())
{
	$photo_form .= '<option>' . $option->gallery . '</option>';
}

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.