Output data from MYSQL with php and putting into forms.

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
kennyg
Forum Newbie
Posts: 1
Joined: Sat Jun 09, 2007 11:42 pm

Output data from MYSQL with php and putting into forms.

Post by kennyg »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

<? 
$i=0; 
while ($i < $num) { 
$id=mysql_result($result,$i,"id"); 
$name=mysql_result($result,$i,"name"); 
$phone=mysql_result($result,$i,"phone"); 
$email=mysql_result($result,$i,"email"); 

?> 

<td width="6025" rowspan="3" align="left"><p class="style1">Target: 
<select name="select"> 
<? echo "<option value='$id'>$name</option>";?> <--------(want to add option here) 
</select> 

<td width="6025" rowspan="3" align="left"><p class="style1"Delete Target: 
<select name="select"> 
<? echo "<option value='$id'>$name</option>";?> <--------(want to add option here) 
</select> 
<? 
$i++;
}
?>
##end of code

Lets say with every line of results I draw out from MySQL and processed into variables with PHP.

How can I actively add a '<option value ='$id'> $name </option>' in the 2 places I want to everytime the loop hooks up?

I tried the above code which I written, it works, it does show all the $name with <options> but in the end it also shows all the unwanted HTML code. The segment between the 2 php sections is being looped many times as well. How can I skip that


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The loop surrounds most of the code posted. Since you wish to only have the options, the loop should only surround that.

Because you have two selects with identical options you may want to cache the information of the first run so it's simple to recreate it again for the second. A simple illustration of this is to store the data into an array. Also, make sure the elements have names.
Post Reply