hey guys i was woundering if it was possible to connect and grab infromation from a database triggered by a drop down menu click in php .... or will i have t o learn java and figure it out there .. im sure there is a way tho somone help meo ut im new to php ;)

Recommended Answers

All 3 Replies

Yes this is a smiple way but when your data become too important, you may wish to use Ajax combined with your menu. This way you can make calls to your server which gives back the data requested.

Here is an examlpe of how I used a dynamic select box using PHP.

In this case I have a table called "facilities" and display the information in the select options by calling the information from the db.
I further set the variable "$sticky" to retain the values upon error checking so the user has the value they originally entered.

<?php
$result = mysql_query("SELECT * FROM facilities ORDER BY Street1 ASC") or 
die(mysql_error());
$sticky= '';
if (isset($_POST['facility']))
$sticky = ($_POST['facility']);
$pulldown1 = '<select name="facility">';
$pulldown1 .= '<option></option>';
 while($row = mysql_fetch_array($result))
            {
if($row['FacilitiesID'] == $sticky) {
$pulldown1 .= "<option selected value=\"{$row['FacilitiesID']}\">
{$row['Street1']}&nbsp;-&nbsp;
{$row['City']}&nbsp;-&nbsp;
{$row['Name']}
</option>\n";
} else {
$pulldown1 .= "<option value=\"{$row['FacilitiesID']}\">
{$row['Street1']}&nbsp;-&nbsp;
{$row['City']}&nbsp;-&nbsp;
{$row['Name']}
</option>\n";
}
}
$pulldown1 .= '</select>';
echo $pulldown1;    
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.