I have this table which contains the following columns.
- Id
- place_id
- name
- latitude
- longitude
- offers
I have to get the offers given an array of place IDs. But the way I have implemented this, it doesn't return any results. Below is my request.
http://localhost:8001/googleplaces/getOffers.php?place_id[]=%22epc888%22&place_id[]=%22epc999%22
Below is the PHP script I wrote.
<?php
$response = array();
$pid =array();
require_once __DIR__ . '/db_connect.php';
$db = new DB_CONNECT();
if (isset($_GET["place_id"])) {
$pid = $_GET['place_id'];
$result = mysql_query("SELECT * FROM places WHERE place_id IN ($pid)");
if (!empty($result)) {
// check for empty result
if (mysql_num_rows($result) > 0) {
$result = mysql_fetch_array($result);
$place = array();
$place["place_id"] = $result["place_id"];
$place["offers"] = $result["offers"];
// success
$response["success"] = 1;
// user node
$response["place"] = array();
array_push($response["place"], $place);
// echoing JSON response
echo json_encode($response);
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No offers found";
// echo no users JSON
echo json_encode($response);
}
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No offers found";
// echo no users JSON
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "place_id is missing";
// echoing JSON response
echo json_encode($response);
}
?>
Though there are couple of records satisfying the above request, this is the response I get.
{"success":0,"message":"No offers found"}
What am I doing wrong here? Please advice. I am new to PHP.