=") == 1) error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED); else error_reporting(E_ALL & ~E_NOTICE); // return states of country if ($_GET['action'] == 'get_states') { $sCountryName = $GLOBALS['MySQL']->escape($_GET['_value']); $aRet[] = array(0 => 'any'); $aStates = $GLOBALS['MySQL']->getPairs("SELECT * FROM `s85_states` WHERE `country_code`='{$sCountryName}'", 'id', 'state_name'); foreach ($aStates as $iStateId => $sStateName) { $aRet[] = array($iStateId => $sStateName); } // echo '
';
    // print_r($aRet);

    require_once('classes/Services_JSON.php');
    $oJson = new Services_JSON();
    header('Content-Type:text/javascript');
    echo $oJson->encode($aRet);
    //echo json_encode($aRet);
    //echo json_last_error() ;
    exit;
}
if ($_GET['action'] == 'get_regions') {
    $iStateID = (int)$_GET['_value'];

    $aRet[] = array(0 => 'any');
    $aRegions = $GLOBALS['MySQL']->getPairs("SELECT * FROM `s85_regions` WHERE `state_id`='{$iStateID}'", 'id', 'region_name');
    foreach ($aRegions as $iRegionId => $sRegionName) {
        $aRet[] = array($iRegionId => $sRegionName);
    }

    require_once('classes/Services_JSON.php');
    $oJson = new Services_JSON();
    header('Content-Type:text/javascript');
    //echo json_encode($aRet);
    echo $oJson->encode($aRet);
    //echo json_last_error() ;
    exit;
}

$sCountryOptions = '';
$aCountries = $GLOBALS['MySQL']->getPairs("SELECT * FROM `s85_countries`", 'country_code', 'country_name');
foreach ($aCountries as $sCode => $sName) {
    $sCountryOptions .= '';
}
$sCountries = '';

echo <<

    
    AJAX chain selectors with jQuery demo
    
    
    
    
    

 
{$sCountries}
EOF; if ($_POST) { // draw debug information echo '
';
    print_r($_POST);
    echo '
'; } ?>

back to original article page