Page 1 of 1

Output data from MYSQL with php and putting into forms.

Posted: Sat Jun 09, 2007 11:44 pm
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]

Posted: Sun Jun 10, 2007 12:44 am
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.