Пример #1
0
    } else {
        $lat = array(0, 0);
    }
    return $lat;
}
// end of function
$name_keyword = $_REQUEST['name'];
$parent_categories = $_REQUEST['parent_categories'];
$sql_search_view = "SELECT\r\r\npostcode_location.id,\r\r\npostcode_location.main_cat_id,\r\r\npostcode_location.item_price,\r\r\npostcode_location.town,\r\r\npostcode_location.status,\r\r\npostcode_location.lat,\r\r\npostcode_location.lang,\r\r\npostcode_location.date,\r\r\nad_title_description.id,\r\r\nad_title_description.postcode_loaction_id,\r\r\nad_title_description.title,\r\r\nad_title_description.description,\r\r\nad_title_description.url\r\r\n\r\r\nFROM\r\r\npostcode_location\r\r\n\r\r\nInner Join ad_title_description ON postcode_location.id = ad_title_description.postcode_loaction_id\r\r\n\r\r\nWHERE  \r\r\npostcode_location.status ='1' ";
if (!empty($name_keyword)) {
    $bykeyword = " AND ad_title_description.title like '%" . $name_keyword . "%' ";
} else {
    $bykeyword = " ";
}
if (!empty($parent_categories)) {
    $ids = search_sub_cat($parent_categories);
    $by_category = " AND postcode_location.main_cat_id IN (" . $ids . ") ";
} else {
    $by_category = " ";
}
if (!empty($_POST['region'])) {
    $lat_lang = get_lan_lat($_POST['region']);
    $by_mils = " AND postcode_location.id IN(SELECT id FROM ( SELECT z.id, z.postcode, z.companyname, z.town, z.lat, z.lang, p.radius, p.distance_unit * DEGREES(ACOS(COS(RADIANS(p.latpoint)) * COS(RADIANS(z.lat)) * COS(RADIANS(p.longpoint - z.lang)) + SIN(RADIANS(p.latpoint)) * SIN(RADIANS(z.lat)))) AS distance FROM postcode_location AS z JOIN ( /* these are the query parameters */ SELECT " . $lat_lang['lat'] . " AS latpoint, " . $lat_lang['lng'] . " AS longpoint, " . $_POST['miles'] . " radius, 69.0 AS distance_unit ) AS p WHERE z.lat BETWEEN p.latpoint - (p.radius / p.distance_unit) AND p.latpoint + (p.radius / p.distance_unit) AND z.lang BETWEEN p.longpoint - (p.radius / (p.distance_unit * COS(RADIANS(p.latpoint)))) AND p.longpoint + (p.radius / (p.distance_unit * COS(RADIANS(p.latpoint)))) ) AS d WHERE distance <= radius ORDER BY distance)";
} else {
    $by_mils = " ";
}
$cdate = date('Y-m-d');
$sql_search_view = $sql_search_view . $bykeyword . $by_category . $by_mils;
$result_search_view = mysql_query($sql_search_view);
$num_rows_views = mysql_num_rows($result_search_view);
$get_postcode = mysql_fetch_array($result_search_view);
Пример #2
0
 function search_sub_cat($tree, $id)
 {
     if (empty($tree->{u('Группа')})) {
         return null;
     }
     foreach ($tree->{u('Группа')} as $group) {
         if ($group->{u('Ид')} == $id) {
             return $group;
         }
         if ($res = search_sub_cat($group->{u('Группы')}, $id)) {
             return $res;
         }
     }
     return null;
 }