Update Help

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
ajsharpe
Forum Newbie
Posts: 1
Joined: Thu May 15, 2008 1:06 pm

Update Help

Post 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
timsewell
Forum Newbie
Posts: 21
Joined: Tue Feb 26, 2008 5:43 am
Location: Hove, England

Re: Update Help

Post 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>";
Post Reply