dongzuo4666 2016-11-20 09:48
浏览 43

参考具有变量的HAVING子句中的列别名

I am trying to get data from database with the following statement,but it doesn't work. Here is my php that was called by ajax to return json data to be represented on map The problem is that it doesn't return anything if the HAVING clause take the value as variable.

<?php
$CustomerName=$_POST["Cust_Name"];

# Connect to MySQL database
$conn = new PDO('mysql:host=localhost;dbname=CustomersDB','root','admin');

# Build SQL SELECT statement including x and y columns
$sql = "SELECT *, _delivery_location_1_coordinates__latitude AS x, _delivery_location_1_coordinates__longitude AS y FROM customers HAVING nick_name_ = '".$CustomerName."'";
if (isset($_GET['bbox']) || isset($_POST['bbox'])) {
$bbox = explode(',', $_GET['bbox']);
$sql = $sql . ' WHERE x <= ' . $bbox[2] . ' AND x >= ' . $bbox[0] . ' AND y <= ' . $bbox[3] . ' AND y >= ' . $bbox[1];
}

$rs = $conn->query($sql);
if (!$rs) {
echo 'An SQL error occured.
';
exit;
}

$geojson = array(
'type'      => 'FeatureCollection',
'features'  => array()
);

while ($row = $rs->fetch(PDO::FETCH_ASSOC)) {
$properties = $row;
# Remove x and y fields from properties (optional)
unset($properties['x']);
unset($properties['y']);
$feature = array(
    'type' => 'Feature',
    'geometry' => array(
        'type' => 'Point',
        'coordinates' => array(
            $row['x'],
            $row['y']
        )
    ),
    'properties' => $properties
);
# Add feature arrays to feature collection array
array_push($geojson['features'], $feature);
}

header('Content-type: application/json');
echo json_encode($geojson, JSON_NUMERIC_CHECK);
$conn = NULL;
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2024-五一综合模拟赛
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭