Jump to content

Recommended Posts

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 .. ??

Link to comment
https://forums.phpfreaks.com/topic/266624-help-making-a-dynamic-select-menu/
Share on other sites

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>';
?>

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.