Jump to content

Help making a dynamic select menu ..


spacepoet

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

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.