/    Sign up×
Community /Pin to ProfileBookmark

Echo data into a drop-down menu..

Hi i have this code.. How would i go about echoing the text into a drop-down menu?

Thanks, Fet

[code=php]
<?
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);
?>

[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@bokehMar 08.2006 — [code=php]echo '<option value="'.$row['Nav_Bar'].'">'.$row['Nav_Bar'].'</option>'."n"; [/code]
Copy linkTweet thisAlerts:
@avaMar 09.2006 — [code=php]echo "<option value="$row['Nav_Bar']">$row['Nav_Bar']</option>";[/code]
Copy linkTweet thisAlerts:
@bokehMar 09.2006 — [code=php]echo "<option value="$row['Nav_Bar']">$row['Nav_Bar']</option>";[/code][/QUOTE]That code raises an error as follows: [CODE]Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING[/CODE]If 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.[code=php]echo "<option value="{$row['Nav_Bar']}">{$row['Nav_Bar']}</option>";[/code]Personally I think that is really ugly due to the escapes but I have noticed Nogdog writes his double quoted string literals like this:[code=php]echo "<option value='{$row['Nav_Bar']}'>{$row['Nav_Bar']}</option>";[/code]which looks a lot tidier.
×

Success!

Help @scottyrob spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...