Hi there,
Trying to have a selectbox that queries the database which contains two fields countryID and countryName and outputs countryID. I can get it to work ok but not when I put
if($form->value("country") == "$row[countryID]"){ echo "selected"; }
which needs to be in to write the value to my procedures. If someone would be so kind to point me in the right direction and tell me what syntax mistake I am making it would be a great help.
Thanks very much
The code below works but I need to insert if($form->value("country") == "$row[countryID]"){ echo "selected"; } where it says HERE, what is the best way of doing this?
<?php
$p2=mysql_query("SELECT countries.countryID, countries.countryName FROM countries") or die(mysql_error());
echo "<select name=country>";
while($row=mysql_fetch_assoc($p2)) {
echo "<option value=$row[countryID]HERE>$row[countryName]</option>";
}
echo "</select>";
?>
My shocking attempt at it which I keep getting errors with.
<?php
$p2=mysql_query("SELECT countries.countryID, countries.countryName FROM countries") or die(mysql_error());
echo "<select name=country>";
while($row=mysql_fetch_assoc($p2)) {
echo "<option value=$row[countryID] {if($form->value("country") == "$row[countryID]"){ echo "selected"; }}>$row[countryName]</option>";
}
echo "</select>";
?>