Jump to content

Dynamic dropdown menu!


Rafi2012

Recommended Posts

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?

 

 

 

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>";
//.......

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.