Displaying dropdown list from DB table & printing selected
Posted: Thu Jan 21, 2010 12:39 am
Hi Everyone,
I am new in php world, I am able to display a drodown list having all the fields from a table called species_master, but not able to print, i got this code from a website, not sure I really need to use it, working but later I also need to store it into some other table kind of stuff..
Here is code for "display dropdown list for all the table fields.
PHP CODE
$sql = mysql_query("SELECT species_primary_common_name FROM Species_master ORDER BY species_primary_common_name");
while($row = mysql_fetch_assoc($sql))
{
$data1 .= "<option value='{$row['species_id']}'>{$row['species_primary_common_name']}</option>";
}
HTML CODE-
<tr>
<td align=right>Species Primary Common Name:</td>
<td>
<select id="species_master" name="data1" style="width: 222px;">
<?php
echo $data1;
?>
</select>
</td>
</tr>
Please Can Anyone suggest me how easily i can solve this issue..Thanks in Advance!!
Also later in other file called tracktrees.php i am using this line to print the dropdown choosen value, but getting warning,
$specresult = mysql_query("SELECT * FROM Species_master WHERE species_id=".$_POST["data1"]");
echo "$specresult";
Thanks once again!!
I am new in php world, I am able to display a drodown list having all the fields from a table called species_master, but not able to print, i got this code from a website, not sure I really need to use it, working but later I also need to store it into some other table kind of stuff..
Here is code for "display dropdown list for all the table fields.
PHP CODE
$sql = mysql_query("SELECT species_primary_common_name FROM Species_master ORDER BY species_primary_common_name");
while($row = mysql_fetch_assoc($sql))
{
$data1 .= "<option value='{$row['species_id']}'>{$row['species_primary_common_name']}</option>";
}
HTML CODE-
<tr>
<td align=right>Species Primary Common Name:</td>
<td>
<select id="species_master" name="data1" style="width: 222px;">
<?php
echo $data1;
?>
</select>
</td>
</tr>
Please Can Anyone suggest me how easily i can solve this issue..Thanks in Advance!!
Also later in other file called tracktrees.php i am using this line to print the dropdown choosen value, but getting warning,
$specresult = mysql_query("SELECT * FROM Species_master WHERE species_id=".$_POST["data1"]");
echo "$specresult";
Thanks once again!!