<?php
class addressctrl{
    public function allcountry(){
        include_once('../Model/address.php');
        $dbobj=new addressdb();
        $result=$dbobj->all_country();
        return $result;
    }
    public function allstate($countrycode){
        include_once('../Model/address.php');
        $dbobj=new addressdb();
        $result=$dbobj->all_state($countrycode);
        return $result;
    }
    public function allcity($statecode){
        include_once('../Model/address.php');
        $dbobj=new addressdb();
        $result=$dbobj->all_city($statecode);
        return $result;
    }
    public function countryname($countrycode){
        include_once('../Model/address.php');
        $dbobj=new addressdb();
        $result=$dbobj->country_name($countrycode);
        return $result;
    }
    public function statename($statecode){
        include_once('../Model/address.php');
        $dbobj=new addressdb();
        $result=$dbobj->state_name($statecode);
        return $result;
    }
    public function cityname($citycode){
        include_once('../Model/address.php');
        $dbobj=new addressdb();
        $result=$dbobj->city_name($citycode);
        return $result;
    }
}
?>

<?php
if(isset($_POST['stateallfromcountry'])){
    $countrycode=$_POST['stateallfromcountry'];
    include_once('../Model/address.php');
    $dbobj=new addressdb();
    $result=$dbobj->all_state($countrycode);
    echo "<option></option>";
    foreach($result as $row){
        $id=$row['id'];
        $name=$row['name'];
        echo "<option value='$id'>$name</option>";
    }
}
?>

<?php
if(isset($_POST['cityallfromstate'])){
    $statecode=$_POST['cityallfromstate'];
    include_once('../Model/address.php');
    $dbobj=new addressdb();
    $result=$dbobj->all_city($statecode);
    //echo "<option value='".$statecode."'>".$statecode."</option>";
    foreach($result as $row){
        $id=$row['id'];
        $name=$row['name'];
        echo "<option value='$id'>$name</option>";
    }
}
?>