hello..
i have a question about how to make dependent list menu based on mysql?
actually, i already found some code that helped me a lot but there has a problem that is i want to change 'get' method to 'post' method.
can u all help me or guide me how to change this code.
thank you
i have a question about how to make dependent list menu based on mysql?
actually, i already found some code that helped me a lot but there has a problem that is i want to change 'get' method to 'post' method.
can u all help me or guide me how to change this code.
thank you
Code:
<?php
$state = $county = null; //declare vars
$conn = mysql_connect("localhost", "root", "12345");
$db = mysql_select_db('test',$conn);
if(isset($_GET["state"]) && is_numeric($_GET["state"]))
{
$state = $_GET["state"];
}
if(isset($_GET["county"]) && is_numeric($_GET["county"]))
{
$county = $_GET["county"];
}
?>
<script language="JavaScript">
function autoSubmit()
{
var formObject = document.forms['theForm'];
formObject.submit();
}
</script>
<form name="theForm" method="get">
<select name="state" onChange="autoSubmit();">
<option value="state">Select State</option>
<?php
$sql = "SELECT * FROM cat_state";
$countries = mysql_query($sql,$conn);
while($row = mysql_fetch_array($countries))
{
echo ("<option value=\"$row[state_id]\" " . ($state == $row["state_id"]? " selected" : "") . ">$row[state]</option>");
}
?>
</select>
<?php
if($state!= null && is_numeric($state))
{
?>
<select name="county" onChange="autoSubmit();">
<option value="county">Select County</option>
<?php
$sql = "SELECT * FROM cat_county WHERE state_id = $state ";
$countys = mysql_query($sql,$conn);
while($row = mysql_fetch_array($countys))
{
echo ("<option value=\"$row[county_id]\" " . ($county == $row["county_id"]? " selected" : "") . ">$row[county]</option>");
}
?>
</select>
<?php
}
?>
Comment