I'm developing webservice. In Request categories id are like,
$categories_string = 1,2,3,4,5.
In response i have to return json array with whole data (from 3-4 tables) associated with all ids. so i use explode() function for string to array. so after this code my array is,
$category_id_array = explode(',',$categories_string );
So , i got array in $category_id_array.
So Problem is that if there is a data in single categories i have to give response even if there is no data in other categories.
Current Output : From this code if there is data in 3 categories among 4 categories it will give (data of 3 and for 4th one there is no data so it will go to else block) So is there a way to check if once go to if block never go to else block or any other logic for this functionality.
Expected Output : Functionality is that among 4 categories if there is data in one categories and not in other categories it show only first categories data if data is in 2 categories it will give data of 2 categories vice versa.
Note : I have to use else block here (if there is no data in all categories than it must respond with else block)
So for that i use below code.
foreach ($category_id_array as $single_cat_value) {
$res_whole_criteria = $this->db->query("SELECT * , ( 3959 * ACOS( COS( RADIANS( '$latitude' ) ) * COS( RADIANS( latitude ) ) * COS( RADIANS( longitude ) - RADIANS( '$longitude' ) ) + SIN( RADIANS( '$latitude' ) ) * SIN( RADIANS( latitude ) ) ) ) AS distance, information_business.name AS business_name FROM information_business LEFT JOIN category ON information_business.category_id = category.id LEFT JOIN offers ON offers.category_id = category.id WHERE category.id = '$single_cat_value' HAVING distance < 10 ORDER BY distance");
$row_whole_criteria = $res_whole_criteria->result();
echo "<pre>";
print_r($row_whole_criteria);
$business_id = $row_whole_criteria['0']->business_id;
// code for count business_wise_like starts here
$like_count_businesswise = $this->db->query("SELECT COUNT( id ) AS business_wise_like FROM `business_likes` WHERE business_id = '$business_id'");
$row_like_businesswise = $like_count_businesswise->result();
$businesswisecount = $row_like_businesswise['0']->business_wise_like;
// code for count business_wise_like ends here
if($res_whole_criteria -> num_rows > 0)
{
$response['success'] = "1";
$response['message'] = "List found for near by Business Data";
$response["data"] = array();
$counter = 0;
foreach($row_whole_criteria as $row)
{
$data = array();
$offerimage = $row->image;
$businessimage = $row->business_image;
$data['Primary Offer Discount'] = $row->discount;
$data['Offer Image'] = $_SERVER["HTTP_HOST"]."/dealsnow/public/images/CATEGORIES/"."$offerimage";
$data['Business Type'] = $row->name;
$data['Business Name'] = $row->business_name;
$data['Business Information']=$row->business_desc;
$data['Business Image'] = $_SERVER["HTTP_HOST"]."/dealsnow/public/images/business_image/"."$businessimage";
$data['Offer Name'] = $row->title;
$data['Offer Address'] = $row->address;
$data['Phone Number'] = $row->mobile;
$data['Original Price'] = $row->original_price;
$data['business Id'] = $row->business_id;
$data['Expiry Date']= $row->end_date;
$data['Latitude']= $row->latitude;
$data['Longitude']= $row->longitude;
$data['Like Status']= '0';
$data['Favorite Status']= '1';
$data['Like Count']= $businesswisecount;
array_push($response["data"], $data);
$counter++;
}
echo $output2 = json_encode(array('responsedata' => $response));
}
else
{
$response = array();
$response ["success"] = 0;
$response ["message"] = "Error.";
$output2 = json_encode(array('responsedata' => $response));
echo $output2;
}
}
Aucun commentaire:
Enregistrer un commentaire