Hallo zusammen,
ich habe eine funktionierende Datenbankabfrage. Nun möchte ich diese auf Wordpress umbauen. Habe aber leider keine Ahnung wie das geht :-)
Es geht um eine Radiussuche anhand von Geodaten.
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$the_rad_stores = "-1";
if (isset($_POST["the_rad"])) {
$the_rad_stores = $_POST["the_rad"];}
$the_lat_stores = "-1";
if (isset($_POST["the_lat"])) {
$the_lat_stores = $_POST["the_lat"];
}
$the_lng_stores = "-1";
if (isset($_POST["the_lng"])) {
$the_lng_stores = $_POST["the_lng"];
}
mysql_select_db($database_testi, $testi);
$query_stores = sprintf("SELECT id, address, name, lat, lng, ( 6371 * acos( cos( radians(%s) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(%s) ) + sin( radians(%s) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < %s ORDER BY distance LIMIT 0 , 20",
GetSQLValueString($the_lat_stores, "double"),
GetSQLValueString($the_lng_stores, "double"),
GetSQLValueString($the_lat_stores, "double"),
GetSQLValueString($the_rad_stores, "int"));
$stores = mysql_query($query_stores, $testi) or die(mysql_error());
$row_stores = mysql_fetch_assoc($stores);
$totalRows_stores = mysql_num_rows($stores);
?>
Alles anzeigen
Die Geodaten habe ich in den custom fields my_lat und my_lng gespeichert.
the_rad, the_lat und the_lng sind die Daten, wo sich der benutzer gerade befindet.
Nur wie übertrage ich das in eine Wordpress query?
Grüße,
Denis