示例#1
0
/**
 * Districts
 *
 * @param string $search search query
 * @param boolean $pagination limit query by page
 * @param string $where additional conditions
 * @return object $results array of districts objects, $pagination pagination object, $query executed query
 */
function api_world_districts($search = NULL, $pagination = FALSE, $where = NULL)
{
    // definitions
    $return = new stdClass();
    $return->results = array();
    // build query
    $query_table = "world_districts";
    // fields
    $query_fields = "world_districts.*";
    // where
    $query_where = "1";
    // search
    if (strlen($search) > 0) {
        $query_where .= " AND ( world_districts.name LIKE '%" . $search . "%' )";
    }
    // conditions
    if (strlen($where) > 0) {
        $query_where = "( " . $query_where . " ) AND ( " . $where . " )";
    }
    // order
    $query_order = api_queryOrder("name ASC");
    // pagination
    if ($pagination) {
        $return->pagination = new str_pagination($query_table, $query_where, $GLOBALS['navigation']->filtersGet());
        // limit
        $query_limit = $return->pagination->queryLimit();
    }
    // build query
    $return->query = "SELECT " . $query_fields . " FROM " . $query_table . " WHERE " . $query_where . $query_order . $query_limit;
    // execute query
    $results = $GLOBALS['db']->query($return->query);
    while ($result = $GLOBALS['db']->fetchNextObject($results)) {
        $return->results[$result->id] = api_world_district($result);
    }
    // return districts objects
    return $return;
}
<?php

/* -------------------------------------------------------------------------- *\
|* -[ World - Chained Districts JSON ]--------------------------------------- *|
\* -------------------------------------------------------------------------- */
require_once "../core/api.inc.php";
require_once "api.inc.php";
// definitions
$results = array();
// acquire variables
$undefined = $_GET['undefined'];
$idRegion = $_GET['idRegion'];
// add default results
if ($undefined != "FALSE") {
    $results[''] = ucfirst(api_text("undefined"));
}
// build query where
$query_where = " idRegion='" . $idRegion . "'";
// check query
//if(!$GLOBALS['db']->countOf("world_regions",$query_where)){$query_where=" 1";}
// execute the query
$districts = $GLOBALS['db']->query("SELECT * FROM world_districts WHERE" . $query_where . " ORDER BY name ASC");
while ($district = $GLOBALS['db']->fetchNextObject($districts)) {
    $results[$district->id] = api_world_district($district)->name;
}
// encode the results
echo json_encode($results);