Page 1 of 1

Update Help

Posted: Thu May 15, 2008 1:12 pm
by ajsharpe
HI

I have created an update form which is all working as the fucntions its self . But i have a problem with selecting the data to update . I have created a drop down menus that populates from mysql but i need the drop down menu to show the selected value of the partulcar record

Code: Select all

<? echo $rows['animalid']; ?>
that its how ive done it if the values had no drop down boxes
 
 

Code: Select all

Code:
select name="animalid">
        <?
 
$query=("select * from animals");
 
$result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() );
 
while($row=mysql_fetch_array($result)){
 
echo "<OPTION VALUE=".$row['animalid'].">".$row['animal']."</OPTION>";
}
?>
so is it possible to merge theese two bits of code together .

Any help would be grateful Thanks

Re: Update Help

Posted: Thu May 15, 2008 4:29 pm
by timsewell

Code: Select all

echo "<OPTION VALUE=".$row['animalid'].">".$row['animal']."</OPTION>";
maybe:


Code: Select all

 
 
$select = "";
 
while($row=mysql_fetch_array($result)){
 
if ($row[blah] == "blah") {
$select = "selected=\"selected\"";
}
 
echo "<OPTION VALUE=".$row['animalid'].".$select.">".$row['animal']."</OPTION>";