Jump to content

Insert select options into this code


Go to solution Solved by Ch0cu3r,

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>
  • Solution

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>';
}
Edited by Ch0cu3r
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.