daveyah2002 Posted November 11, 2014 Share Posted November 11, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/292412-insert-select-options-into-this-code/ Share on other sites More sharing options...
ginerjm Posted November 11, 2014 Share Posted November 11, 2014 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> Quote Link to comment https://forums.phpfreaks.com/topic/292412-insert-select-options-into-this-code/#findComment-1496335 Share on other sites More sharing options...
Solution Ch0cu3r Posted November 11, 2014 Solution Share Posted November 11, 2014 (edited) 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 November 11, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/292412-insert-select-options-into-this-code/#findComment-1496339 Share on other sites More sharing options...
daveyah2002 Posted November 11, 2014 Author Share Posted November 11, 2014 Thanks for taking the time to reply, I appreciate it. Ginerjm - not quite, it was Ch0cur that pointed out what I needed. With hindsight it looks so obvious!! Ch, I've still got half my hair left thanks to you. Quote Link to comment https://forums.phpfreaks.com/topic/292412-insert-select-options-into-this-code/#findComment-1496348 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.