Page 1 of 1

Displaying dropdown list from DB table & printing selected

Posted: Thu Jan 21, 2010 12:39 am
by pavanesh2009
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!!

Re: Displaying dropdown list from DB table & printing selected

Posted: Thu Jan 21, 2010 3:48 am
by aravona

Code: Select all

$specresult = mysql_query("SELECT * FROM Species_master WHERE species_id=".$_POST["data1"]");
You're not ending your first quotation.

Re: Displaying dropdown list from DB table & printing selected

Posted: Fri Jan 22, 2010 6:52 am
by pavanesh2009
aravona wrote:

Code: Select all

$specresult = mysql_query("SELECT * FROM Species_master WHERE species_id=".$_POST["data1"]");
You're not ending your first quotation.
Thank you very much aravona!!

one more help may be again this could be easier for you but as a new student in php world I feel it slightly difficult,

I have one home template(complete homepage image), which having rectangular boxses , i used <map> their for redirecting to new file, it's working fine too, but now there is one more rectangular box which onclick has to a dropdown list(coming from a db table where user_id=...)

This code is working fine:

$sql = mysql_query("SELECT tree_nickname FROM user_tree_table WHERE user_id=81");

while($row = mysql_fetch_assoc($sql))
{
$data1 .= "<option value='{$row['tree_nickname']}'>{$row['tree_nickname']}</option>";
}
?>

Please suggest how i can achieve it.Thanks in Advance!!

Re: Displaying dropdown list from DB table & printing selected

Posted: Fri Jan 22, 2010 6:56 am
by aravona
Erm, little lost this time. If the codes working what is it you are trying to achieve?

Re: Displaying dropdown list from DB table & printing selected

Posted: Fri Jan 22, 2010 7:27 am
by pavanesh2009
aravona wrote:Erm, little lost this time. If the codes working what is it you are trying to achieve?
Sorry I think I could not explain it properly, Simply i wanted to ask how i can link it using <map> tag in my template.As of now it is redirecting to a new php file having dropdown instead of in the same page reactangular area.

Thanks once again!!