Populating Drop Down with Existing Row

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wolfnipplechips
Forum Commoner
Posts: 32
Joined: Tue Aug 18, 2009 6:46 am
Location: Berkshire, UK

Populating Drop Down with Existing Row

Post by wolfnipplechips »

Hi there,

I have a form which allows users to update information already set in a row. In this case a drop down populated with row items, with the previously specified option in the default position.

Code: Select all

 
 
<?php
include("connect.php"); 
$query="SELECT locationName FROM location";
 
$result = mysql_query ($query);
echo "<select name='eventLocation'><option value=''>'$row['eventLocation']'</option>";
 
while($nt=mysql_fetch_array($result)){
echo "<option value='$nt[locationName]'>'$nt[locationName]'</option>";
 
}
echo "</select>";
?>
 
 
It worked fine until I tried to get the default value sorted. Now I get a 'unexpected T_ENCAPSED_AND_WHITESPACE' on that line.

Can anyone give me any advice on what I'm doing wrong here. Should I echo the row or not?

Many thanks.
wolfnipplechips
Forum Commoner
Posts: 32
Joined: Tue Aug 18, 2009 6:46 am
Location: Berkshire, UK

Re: Populating Drop Down with Existing Row

Post by wolfnipplechips »

Cheers for the tips! I appreciate the help.

I've changed the line to

Code: Select all

echo "<select name='eventLocation'><option value=''>{$row['eventLocation']}</option>";
Thanks again!
Post Reply