spacepoet Posted August 3, 2012 Share Posted August 3, 2012 Hello: I am trying to make a dynamic select menu, but can not seem to figure out what I am doing wrong. The idea is to select the list in the database (spon_id and shout_photo_caption) and display the list as an HTML select menu. Plus to have the database "remember" what selection was picked the last time the user used the select menu and inserted it into the database. I am a bit stuck ... Here is what I have: <? $query = "SELECT shout_id, shout_photo_caption FROM myShoutout ORDER BY shout_listorder"; $result = mysql_query($query); $num_rows = mysql_num_rows($result); echo '<select>'; while ($num_rows = mysql_num_rows($result)) { echo '<option value='" . $row['shout_id'] . '">' . $row['shout_photo_caption'] . '</option>'; } echo '</select>'; ?> What am I missing .. ?? Quote Link to comment https://forums.phpfreaks.com/topic/266624-help-making-a-dynamic-select-menu/ Share on other sites More sharing options...
Drummin Posted August 3, 2012 Share Posted August 3, 2012 Don't use short tags, eg. <?. Use full opening tag <?php <?php //assuming variable $remember is set by session or other query $query = "SELECT shout_id, shout_photo_caption FROM myShoutout ORDER BY shout_listorder"; $result = mysql_query($query); echo '<select>'; while ($row=mysql_fetch_array($result)) { $selected =(isset($remember) && $remember==$row['shout_id'] ? ' selected="selected"' : ''); echo "<option value="{$row['shout_id']}"$selected>{$row['shout_photo_caption']}</option>"; } echo '</select>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/266624-help-making-a-dynamic-select-menu/#findComment-1366519 Share on other sites More sharing options...
spacepoet Posted August 3, 2012 Author Share Posted August 3, 2012 Thank you! I had to tweak this one line so it is now like this: echo "<option value='{$row['shout_id']}'>{$row['shout_photo_caption']}</option>"; but now works fine! I appreciate the help. Quote Link to comment https://forums.phpfreaks.com/topic/266624-help-making-a-dynamic-select-menu/#findComment-1366693 Share on other sites More sharing options...
Drummin Posted August 4, 2012 Share Posted August 4, 2012 Ya, my bad not escaping those inner quotes. Glad you got it working. Quote Link to comment https://forums.phpfreaks.com/topic/266624-help-making-a-dynamic-select-menu/#findComment-1366702 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.