我可以显示所有结果,但当我调整代码以尝试更具体地查询时,它返回42s22{“error”:{“text”:sqlstate[42s22]:column not found:1054 unknown column'plant'in'where clause'}即使有一个具有plant值的列,它也会显示此错误。
<?php
require '.././libs/Slim/Slim.php';
require '.././include/db.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
$app->get('/location/all', function(){
$sql = "SELECT * FROM plant_location";
try{
$db = new db();
$db = $db->connect();
$stmt = $db->query($sql);
$customers = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
echo json_encode($customers);
} catch(PDOException $e){
echo '{"error": {"text": '.$e->getMessage().'}';
}
});
$app->get('/location/plant/:plant', function($plant){
$sql = "SELECT * FROM plant_location WHERE plant=$plant";
try{
$db = new db();
$db = $db->connect();
$stmt = $db->query($sql);
$customers = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
echo json_encode($customers);
} catch(PDOException $e){
echo '{"error": {"text": '.$e->getMessage().'}';
}
});
$app->run();
?>
sql:我试着用plant过滤结果
CREATE TABLE `plant_location` (
`id` int(11) NOT NULL,
`plant` varchar(255) NOT NULL,
`latitude` varchar(255) NOT NULL,
`longitude` varchar(255) NOT NULL,
`image` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `plant_location` (`id`, `plant`, `latitude`, `longitude`, `image`) VALUES
(1, 'Plant', '14.396033', '121.0452128', '//'),
(2, 'Plant B', '14.3967839', '121.0444142', ''),
(3, 'Bawang', '14.3975636', '121.0447081', ''),
(4, 'Bawang', '14.395036', '121.044177', '');
例如,如果我使用/location/plant/bawang,我想检索id为3和4的条目
(3、霸王、14.3975636、121.0447081、4、霸王、14.395036、121.044177、1);
1条答案
按热度按时间1hdlvixo1#
多亏了埃德·科特雷尔,我找到了答案。我把它贴在这里以防万一有人也需要答案。分享就是关心,我想
分贝