I can display all results but when I tweaked the code to try to query more specifically, it returns 42s22 {"error": {"text": SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Plant' in 'where clause'} even though there a column with plant value, it shows this error.
<?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: I was trying to filter results using the 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', '');
For example if I used /location/plant/Bawang I want to retrieve the entry with id 3 and 4
(3, 'Bawang', '14.3975636', '121.0447081', ''), (4, 'Bawang', '14.395036', '121.044177', '');