Menu
I have a script that contains 3 dropdown list. 1 country 2 region 3 city
I wonder how i can populate the script from database
because if i leave it like this works fine but i want to extract the country from database mysql. if somebody knows how can i do that please help.
[code=php]
function createDropDownList() {
$mysqli = mysqli_connect("host", "un", "pw", "db");
$dbname = 'database';
$sql = "SHOW TABLES FROM $dbname";
$result = mysqli_query($mysqli, $sql);
echo "<select name'selectName'>";
while ($row = mysqli_fetch_array($result)) {
$tempCounter = 0;
echo "<option value='".$row[$tempCounter]."'>".ucfirst($row[$tempCounter])."</option<br/>";
}
echo "</select>";
}
[/code]
<select style="width: 15em" name="country" id="country" onchange="setStates();">
<option selected="selected">Select your Country</option>
<option value="Germany">Germany</option>
<option value="Morocco">Morocco</option>
<option value="United Kingdom">United Kingdom</option>
</select>
</div></td>
</tr>
<tr>
<td><div align="right">
<label for="label">Your Region</label>
</div></td>
<td>
<div align="left">
<select style="width: 15em" name="region" id="region" onchange="setCities();">
<option selected="selected">Select your Region</option>
</select>
</div></td>
</tr>
<tr>
<td><div align="right">
<label for="city">Your City</label>
</div></td>
<td><div align="left">
<select style="width: 15em" name="city" id="city">
</select>
</div></td>
<i>
</i><SCRIPT language=JavaScript>
function reload(form)
{
var val=form.state_id.options[form.state_id.options.selectedIndex].value;
//var cid=form.clubid.value;
self.location='statetest2.php' + '?state_id=' + val ;
}
</script>
[code=php]if(isset($_GET['state_id'])and strlen($_GET['state_id']) > 0){
$state_id = $_GET['state_id'];
echo '<select style="width: 15em" name="state_id" id="state_id" onchange="reload(this.form)">';
$statesql = "SELECT * FROM ebar_state
";
$stateres = mysql_query($statesql);
if ($stateres) {
while ($state = mysql_fetch_assoc($stateres) ) {
if ($state_id == $state['id']) {
echo '<option value="'.$state['id'].'" selected="selected">'.$state['state'].'</option>';
} else {
echo '<option value="'.$state['id'].'">'.$state['state'].'</option>';
}
}
}
echo '</select>';
echo '<select style="width: 15em" name="county" id="county">';
$cquery = mysql_query("SELECT * FROM ebar_county
WHERE state_id
='".$state_id."' ORDER BY county
");
if($cquery) {
while ($co = mysql_fetch_assoc($cquery) ) {
echo '<option value="'.$co['id'].'">'.$co['county'].'</option>';
}
} else {
echo 'umm no.' .mysql_error();
}
} else {
echo '<select style="width: 15em" name="state_id" id="state_id" onchange="reload(this.form)">';
$statesql = "SELECT * FROM ebar_state
";
$stateres = mysql_query($statesql);
if ($stateres) {
while ($state = mysql_fetch_assoc($stateres) ) {
echo '<option value="'.$state['id'].'">'.$state['state'].'</option>';
}
}
echo '</select>';
}[/code]
[code=php]
// connect to mysql
// execute your query
echo "<SELECT id="myDropDown">"
while ($row = mysql_fetch_row($your_query_results) {
echo "<OPTION>{$row[0]}</OPTION>"
}
echo "</SELECT>"
[/code]
[CODE]
var mySelectElement = document.getElementById("myDropDown");
var myListOfOptions = mySelectElement.getElementsByTagName("OPTION");
[/CODE]
0.1.9 — BETA 5.24