Click to See Complete Forum and Search --> : Echo data into a drop-down menu..


scottyrob
03-08-2006, 02:38 PM
Hi i have this code.. How would i go about echoing the text into a drop-down menu?

Thanks, Fet

<?
require 'db_connect.php';

$query = ("SELECT Nav_Bar FROM Front_Page");
$result = mysql_query($query);

if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}

while ($row = mysql_fetch_assoc($result)) {
echo $row['Nav_Bar'];
}

mysql_free_result($result);
?>

bokeh
03-08-2006, 05:03 PM
echo '<option value="'.$row['Nav_Bar'].'">'.$row['Nav_Bar'].'</option>'."\n";

ava
03-09-2006, 06:57 AM
echo "<option value=\"$row['Nav_Bar']\">$row['Nav_Bar']</option>";

bokeh
03-09-2006, 08:07 AM
echo "<option value=\"$row['Nav_Bar']\">$row['Nav_Bar']</option>";That code raises an error as follows: Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRINGIf you are going to post a reply at least make sure your code works first. When an array element is being used inside a double quoted string literal the array element must be encapsulated in curly braces.echo "<option value=\"{$row['Nav_Bar']}\">{$row['Nav_Bar']}</option>";Personally I think that is really ugly due to the escapes but I have noticed Nogdog writes his double quoted string literals like this:echo "<option value='{$row['Nav_Bar']}'>{$row['Nav_Bar']}</option>";which looks a lot tidier.