Access Database from Dropdown list

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
cjan1234
Forum Newbie
Posts: 2
Joined: Fri Nov 17, 2006 8:33 am

Access Database from Dropdown list

Post by cjan1234 »

Newbie Here!!!!

When I click on a selection from a dropdown list I need to access information stored in a database and echo that information on the same page as the dropdown list.

Any help would be appreciated.


Thanks,
timclaason
Forum Commoner
Posts: 77
Joined: Tue Dec 16, 2003 9:06 am
Location: WI

Dropdown

Post by timclaason »

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]


You could do something like this:

Code: Select all

<FORM METHOD="POST" ACTION="whateverpage.php">
<TABLE>
<TR>
<TD>Dropdown List</TD>
<TD><SELECT SIZE='1' NAME='dropdownlist'>
<OPTION>Click in this dropdown list</OPTION>
<!--Start PHP Code-->
$query = "SELECT * FROM table"; //or whatever the query is
$SQL = mysql_query($query, $db_link);
while($row = mysql_fetch_array($SQL)) {
print("<OPTION>" . $row['field_from_table'] . "</OPTION>");
}
<!--End PHP Code-->
</SELECT></TD>
</TR>
</TABLE>
<INPUT TYPE='SUBMIT' VALUE='Submit'>

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]
cjan1234
Forum Newbie
Posts: 2
Joined: Fri Nov 17, 2006 8:33 am

Thanks timclaason

Post by cjan1234 »

Thanks, I will try that
Post Reply