データベースから値を取得する関数が 2 つあります。関数内の接続 ( $connection
) にアクセスすると、DB にアクセスできません。私はmysql + PHPを使用しています
コードは次のとおりです。
<?php
function getTierOne()
{
require_once('../config.php');
$provincequery="SELECT provinces.ProvinceID, provinces.ProvinceName FROM provinces WHERE ProvinceID > 0";
$result = $connection->query($provincequery);
while($province = $result->fetch_assoc())
{
echo '<option value="'.$province['ProvinceID'].'">'.$province['ProvinceName'].'</option>';
}
}
//**************************************
// First selection results //
//**************************************
if(isset($_GET['func']) && $_GET['func'] == "province")
{
province($_GET['drop_var']);
}
function province($drop_var)
{
require_once('../config.php');
$district_query = "SELECT districts.DistrictID, districts.DistrictName, provinces.ProvinceName FROM districts, provinces WHERE provinces.ProvinceID=districts.ProvinceID AND districts.DistrictID > 0 AND provinces.ProvinceID='$drop_var'";
$district_query_run= $connection->query($district_query);
echo '<select name="district" id="district" style="width:150px;">
<option value="0" disabled="disabled" selected="selected">Select Your District</option>';
while($district= $district_query_run->fetch_assoc())
{
echo '<option value="'.$district['DistrictID'].'">'.$district['DistrictName'].'</option>';
}
echo '</select>';
echo "<script type=\"text/javascript\">
$('#wait_2').hide();
$('#district').change(function(){
$('#wait_2').show();
$('#result_2').hide();
$.get(\"ProDisPds/func.php\", {
func: \"district\",
drop_var: $('#district').val()
}, function(response){
$('#result_2').fadeOut();
setTimeout(\"finishAjax_tier_three('result_2', '\"+escape(response)+\"')\", 400);
});
return false;
});
</script>";
}
?>