Beispiel #1
0
/**
 * Regions
 *
 * @param string $search search query
 * @param boolean $pagination limit query by page
 * @param string $where additional conditions
 * @return object $results array of regions objects, $pagination pagination object, $query executed query
 */
function api_world_regions($search = NULL, $pagination = FALSE, $where = NULL)
{
    // definitions
    $return = new stdClass();
    $return->results = array();
    // build query
    $query_table = "world_regions";
    // fields
    $query_fields = "world_regions.*";
    // where
    $query_where = "1";
    // search
    if (strlen($search) > 0) {
        $query_where .= " AND ( world_regions.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_region($result);
    }
    // return regions objects
    return $return;
}
<?php

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