Reputation: 21
I am making select list from database table everything works fine only issue is in option value if the value consist of two words like "New York" it only returns "New". Here is the code
<? $country=intval($_GET['country']);
include('connect-db.php');
$query="SELECT CityName FROM cities WHERE CountryId='$country'";
$result=mysql_query($query);
?>
<select name="city">
<option value="">Select City</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value=<?=$row['CityName']?>><?=$row['CityName']?></option>
<? } ?>
</select>
Upvotes: 0
Views: 5476
Reputation: 1380
You haven't included the "" while giving the values. if you look at the html created for the select box by your code is something like
<option value="new" york>new york</option>
correct solution is given below, just included the quotation while giving value of option tag.
<? $country=intval($_GET['country']);
include('connect-db.php');
$query="SELECT CityName FROM cities WHERE CountryId='$country'";
$result=mysql_query($query);
?>
<select name="city">
<option value="">Select City</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value="<?=$row['CityName']?>"><?=$row['CityName']?></option>
<? } ?>
</select>
Upvotes: 1
Reputation: 136
You'll have to surrond the value in "", the HTML code thinks the York part is just another attribute of the option tag, so:
<option value="<?=$row['CityName']?>"><?=$row['CityName']?></option>
Upvotes: 1
Reputation: 4957
<option value="<?=$row['CityName']?>"><?=$row['CityName']?></option>
The " " .
Upvotes: 1