Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.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 如何在mysql中查看haversine计算中别名的值?_Php_Mysql - Fatal编程技术网

Php 如何在mysql中查看haversine计算中别名的值?

Php 如何在mysql中查看haversine计算中别名的值?,php,mysql,Php,Mysql,我有以下部分代码: $query = "SELECT $table.*, outcodepostcodes.lat, outcodepostcodes.lng ,111.045* DEGREES(ACOS(COS(RADIANS(". $latpoint .")) * COS(RADIANS(outcodepostcodes.lat)) * COS(RADIANS(". $longpoint .") - RADIANS(outcodepostcodes.ln

我有以下部分代码:

$query =  "SELECT $table.*, outcodepostcodes.lat, outcodepostcodes.lng
,111.045* DEGREES(ACOS(COS(RADIANS(". $latpoint ."))
         * COS(RADIANS(outcodepostcodes.lat))
         * COS(RADIANS(". $longpoint .") - RADIANS(outcodepostcodes.lng))
        + SIN(RADIANS(". $latpoint ."))
         * SIN(RADIANS(outcodepostcodes.lat)))) AS distance_in_km
FROM $table     
LEFT JOIN outcodepostcodes
ON UPPER($table.postcode)=outcodepostcodes.outcode
WHERE
$where_no_and
AND 
(hide='0' OR hide IS NULL OR hide='')
HAVING distance_in_km  <= 20
ORDER BY rent $reihenach LIMIT $offset, $rowsPerPage
";
$query=“选择$table.*,outcodepostcodes.lat,outcodepostcodes.lng
,111.045*度(ACOS(弧度(“.$latpoint”))
*COS(弧度(outcodepostcodes.lat))
*COS(弧度(“.$longpoint.”)-弧度(outcodepostcodes.lng))
+SIN(弧度(“.$latpoint.”)
*SIN(弧度(outcodepostcodes.lat)))表示距离(单位:公里)
从$table开始
左联接输出代码邮政编码
在上方($table.postcode)=outcodepostcodes.outcode
哪里
$where_no_和
及
(hide='0'或hide为NULL或hide=''')

距离(单位:km)正常后,我解决了至少一个问题,即警告:

警告:mysql_result()[function.mysql result]:在第668行的/home/properf/public_html/4Tsalepf.php中的mysql结果索引6中未找到以公里为单位的距离

为此,我将别名的名称从distance“u in”km改为distance。显然,这与“identifier quoting”有关。我没有尝试过,但如果我将distance“u in”km括在引号中,它可能也会起作用

但是,我仍然无法访问别名的值。我首先尝试使用子查询,将别名放在主查询中,如下所示:

SELECT distance FROM (
SELECT $table.*, outcodepostcodes.lat, outcodepostcodes.lng
,2*3 AS distance
FROM $table
LEFT JOIN outcodepostcodes
然后还用简单的2*3作为距离来代替哈弗森计算,试图强迫这个结果出现在

$distance=mysql_result($result,$i,“distance”)

但是,当我回显$distance时,它仍然为空,而不是预期的6(即2*3)


非常感谢任何想法。谢谢。

好的,我至少解决了一个问题,那就是警告:

警告:mysql_result()[function.mysql result]:在第668行的/home/properf/public_html/4Tsalepf.php中的mysql结果索引6中未找到以公里为单位的距离

为此,我将别名的名称从distance“u in”km改为distance。显然,这与“identifier quoting”有关。我没有尝试过,但如果我将distance“u in”km括在引号中,它可能也会起作用

但是,我仍然无法访问别名的值。我首先尝试使用子查询,将别名放在主查询中,如下所示:

SELECT distance FROM (
SELECT $table.*, outcodepostcodes.lat, outcodepostcodes.lng
,2*3 AS distance
FROM $table
LEFT JOIN outcodepostcodes
然后还用简单的2*3作为距离来代替哈弗森计算,试图强迫这个结果出现在

$distance=mysql_result($result,$i,“distance”)

但是,当我回显$distance时,它仍然为空,而不是预期的6(即2*3)


非常感谢您的任何想法。谢谢。

您必须连接到数据库,运行查询,获取结果并显示数据。您到底遇到了什么问题?我已添加了其余代码,并在尝试检索别名“distance\u in\u km”时显示了警告。警告:如果您只是在学习PHP,请不要使用the接口。它是如此可怕和危险,以至于在PHP 7中被删除。类似的替换和类似的指南解释了最佳实践。您的用户参数不是,并且有可以利用的。@tadman,谢谢。我现在已经跳过了引号中的引号。在离开3年后,我将返回编程,并且我意识到这非常重要我有几个技术目标要实现(这个主题与其中一个相关)然后将返回到安全问题和PDO/mysqli等。如果有人可以帮助我解决此特定问题,将不胜感激。您必须连接到数据库,运行查询,获取结果并显示数据。您到底有什么问题?我已添加了其余代码,并在尝试重试时显示警告e别名“distance_in_km”。警告:如果您只是在学习PHP,请不要使用该界面。它非常可怕和危险,在PHP7中被删除。类似的替换和类似的指南解释了最佳实践。您的用户参数不是,并且有可利用的参数。@tadman,谢谢。我已经跳过了其中的引用现在是tes。我在离开3年后重新开始编程,我意识到已经发生了很大的变化。我有一些技术目标要实现(与其中一个相关的主题),然后将回到安全问题和PDO/mysqli等方面。如果有人能帮我解决这个特定问题,我将不胜感激。