Rafi2012 Posted April 12, 2012 Share Posted April 12, 2012 I want make the following, (I have already a database with three tables (Countries, Timeline and Category)). 1: list of countries (drop down menu 1), Timeline of the countries history (drop down 2) and Category (drop down 3). 2: The selected values of the drop down menus must show take the information from the database. Can any one help me with the coding? Quote Link to comment https://forums.phpfreaks.com/topic/260788-dynamic-dropdown-menu/ Share on other sites More sharing options...
Muddy_Funster Posted April 12, 2012 Share Posted April 12, 2012 let's see what you've got and where it's going wrong Quote Link to comment https://forums.phpfreaks.com/topic/260788-dynamic-dropdown-menu/#findComment-1336624 Share on other sites More sharing options...
Rafi2012 Posted April 12, 2012 Author Share Posted April 12, 2012 The following is the code for the application i am trying to develop, the selected values from the three drop down menus doesn't show the content from the database! <html> <head> <link href='page.css' rel='stylesheet'> <title> Interactive AGE+ </title> </head> <body> <div class ='wrapper'> <div class ='header2'> <div class='titel'> <p> Interactive AGE+ </p> </div> <div class='user'> <?php include('connectland.php'); ?> </div> </div> <div class ='navbar'> <div class ='holder'> <ul> <li><a href='#'>Home</a></li> <li><a href='#'>Aardrijkskunde</a></li> <li><a href='#'>Economie</a></li> <li><a href='#'>Techniek</a></li> <li><a href='#'>Info</a></li> </ul> <!-- Navigatie knoppen --> </div> </div> <div class ='mainbody'> <div class ='links'> <h1 class='tekst'>Land selecteren</h1><br /> <?php $query = "SELECT landID ,landnaam FROM landen"; $result = mysql_query ($query); $query2 = "SELECT PerID ,Periode FROM periode"; $result2 = mysql_query ($query2); $query3 = "SELECT CatID ,categorie FROM categorien"; $result3 = mysql_query ($query3); echo '<form action="members.php" method="POST">'; echo '<select name="landname" id="landnaam">'; echo '<optgroup label="Landen">'; while($row=mysql_fetch_assoc($result)){ //Array or records stored in $nt $countryname = $row['landnaam']; echo '<option value='. $countryname .'> '. $countryname .' </option>'; } echo '</optgroup>'; echo '</select></td>'; echo '<br />'; echo '<select name="pers" id="perioden">'; echo '<optgroup label="Periodes">'; while($row2=mysql_fetch_assoc($result2)){ //Array or records stored in $nt $periodenaam = $row2['Periode']; echo '<option value='. $periodenaam .'> '. $periodenaam .' </option>'; } echo '</optgroup>'; echo '</select></td>'; echo '<br />'; echo '<select name="cats" id="categorien">'; echo '<optgroup label="Categorie">'; while($row3=mysql_fetch_assoc($result3)){ //Array or records stored in $nt $categorienaam = $row3['categorie']; echo '<option value='. $categorienaam .'> '. $categorienaam .' </option>'; } echo '</optgroup>'; echo '</select></td>'; echo '<br /><br />'; echo '<input class="Knoppen" name="verder" type="submit" align="center" value="Ga verder"/>'; echo '</form>'; ?> </div> <div class='midden'> <?php if (isset($_POST['verder'])){ $land = $_POST['landname']; echo "<h1>$land</h1><br />"; $query = "SELECT informatie FROM landen WHERE landnaam = '$land'"; $result = mysql_query ($query); while ($row=mysql_fetch_assoc($result)) { $info = $row['informatie']; echo nl2br($info); } } ?> </div> <div class='rechts'> </div> </div> <div class ='footer'><center> ©2012</center></div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/260788-dynamic-dropdown-menu/#findComment-1336627 Share on other sites More sharing options...
Muddy_Funster Posted April 12, 2012 Share Posted April 12, 2012 Try using this, I have only sampled the first select group, but it should be easy enough to work out from that <?php function buildMenu($value){//going to use this function to build the option list if(!empty($value)){ $output = "<option value =\"$value\">$value</option>\n"; return $output; } } $query = "SELECT landen.landnaam, periode.Periode, categorien.categorie FROM landen, periode, categorien"; $reusult = mysql_query($query) or die (mysql_error())."<br>------------------<br>$query"); while ($row = mysql_fetch_assoc($result)){ $landMenu[] = buildMenu($row['landen']); $periodMenu[] = buildMenu($row['periode']); $catagorieMenu[] = buildMenu($row['categorie']); } //..... echo "<select name=\"landname\" id=\"landnaam\">"; echo "<optgroup label=\"Landen\">"; foreach($landMenu as $key){ echo $landMenu[$key]; } echo "</optgroup></select>"; //....... Quote Link to comment https://forums.phpfreaks.com/topic/260788-dynamic-dropdown-menu/#findComment-1336630 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.