Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP查询值设置中的问题?_Php_Mysql_Sql_Mamp_Haversine - Fatal编程技术网

PHP查询值设置中的问题?

PHP查询值设置中的问题?,php,mysql,sql,mamp,haversine,Php,Mysql,Sql,Mamp,Haversine,快速提问。我有一个与我的数据库一起工作的SQL查询。但是,我确定如何在我的PHP文件中设置参数,以便它与我的查询一起工作 有什么想法吗?我在php中设置参数和使查询正常工作方面遇到了问题 <?php /* * Following code will list all the products */ // array for JSON response $response = array(); // include db connect class require_once __D

快速提问。我有一个与我的数据库一起工作的SQL查询。但是,我确定如何在我的PHP文件中设置参数,以便它与我的查询一起工作

有什么想法吗?我在php中设置参数和使查询正常工作方面遇到了问题

<?php

/*
 * Following code will list all the products
 */

// array for JSON response
$response = array();

// include db connect class
require_once __DIR__ . '/db_connect.php';

// connecting to db
$db = new DB_CONNECT();

set $orig_lat=32.42; 
set $orig_long=-23.550; 
set $bounding_distance=1;

// get all products from products table
$result = mysql_query(" SELECT * ,((ACOS(SIN($orig_lat * PI() / 180) * SIN(`latitude` * PI() /
180) + COS($orig_lat * PI() / 180) * COS(`latitude` * PI() / 180) *
COS(($orig_long - `longitude`) * PI() / 180)) * 180 / PI()) * 60 *
1.1515) AS `distance` FROM `Location` WHERE ( `latitude` BETWEEN
($orig_lat - $bounding_distance) AND ($orig_lat + $bounding_distance)
AND `longitude` BETWEEN ($orig_long - $bounding_distance) AND
($orig_long + $bounding_distance) ) ORDER BY `distance` ASC limit 1") or die(mysql_error()); 

// check for empty result
if (mysql_num_rows($result) > 0) {
    // looping through all results
    // products node
    $response["Location"] = array();

    while ($row = mysql_fetch_array($result)) {
        // temp user array
       $Location = array();
       $Location["id"] = $row["id"];
       $Location["latitude"] = $row["latitude"];
       $Location["longitude"] = $row["longitude"];



        // push single product into final response array
        array_push($response["Location"], $Location);
    }
    // success
    $response["success"] = 1;

    // echoing JSON response
    echo json_encode($response);
} else {
    // no products found
    $response["success"] = 0;
    $response["message"] = "No Profiles found";

    // echo no users JSON
    echo json_encode($response);
}
?>

这是一个简单的语法问题……与查询对应的值没有被很好地标注。在PHP文件中,不能使用$编写集合和声明变量

原件:

set $orig_lat=32.42; 
set $orig_long=-23.550; 
set $bounding_distance=1;
解决方案:

$orig_lat=32.42; 
$orig_long=-23.550; 
$bounding_distance=1;

这个问题缺乏信息。你能分享你尝试过的东西吗?你遇到了什么问题?通常,你会做一个函数。该函数将包含参数。至少,这些参数可能包括$latitiude和$longitude(在本例中还有$bounding)。@JayBlanchard请参阅修订版editsPlease。它们不再得到维护,而是在使用。相反,请考虑使用PDO,.jayBrcAdAd,它在给应用程序运行时需要给我一个错误,因为它需要从文件中获取引用。然而,这只是删除$orig值前面的“set”的情况。现在好了,谢谢你!