Displaying dropdown list from DB table & printing selected

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
pavanesh2009
Forum Commoner
Posts: 30
Joined: Wed Jan 13, 2010 7:24 am

Displaying dropdown list from DB table & printing selected

Post 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!!
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: Displaying dropdown list from DB table & printing selected

Post by aravona »

Code: Select all

$specresult = mysql_query("SELECT * FROM Species_master WHERE species_id=".$_POST["data1"]");
You're not ending your first quotation.
pavanesh2009
Forum Commoner
Posts: 30
Joined: Wed Jan 13, 2010 7:24 am

Re: Displaying dropdown list from DB table & printing selected

Post 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!!
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: Displaying dropdown list from DB table & printing selected

Post by aravona »

Erm, little lost this time. If the codes working what is it you are trying to achieve?
pavanesh2009
Forum Commoner
Posts: 30
Joined: Wed Jan 13, 2010 7:24 am

Re: Displaying dropdown list from DB table & printing selected

Post 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!!
Post Reply