This query is giving correct result in MySql workbench -
SELECT tbl_visit_info.visitor_id,tbl_visit_info.retailer_id,tbl_retailer.retailer_shop_name,
SUM( IF( tbl_visit_info.activity_type = 1 ,1,0)) AS feedback,
SUM( IF( tbl_visit_info.activity_type = 2 ,1,0)) AS promise_order,
SUM( IF( tbl_visit_info.activity_type = 3 ,1,0)) AS stock,
SUM( IF( tbl_visit_info.activity_type = 6 ,1,0)) AS payment,
tbl_visit_info.date as visit_date
FROM tbl_visit_info,tbl_retailer
where tbl_visit_info.retailer_id=tbl_retailer.retailer_id
and tbl_visit_info.visitor_id=80
group by visitor_id,retailer_id
having date_format(tbl_visit_info.date, '%Y-%m-%d') BETWEEN '2018-07-01' AND '2018-09-02';
But, when I want to pass variables in place of 80 and date range as a variable then it is not giving any result. Query is-
SELECT tbl_visit_info.visitor_id,tbl_visit_info.retailer_id,tbl_retailer.retailer_shop_name,
SUM( IF( tbl_visit_info.activity_type = 1 ,1,0)) AS feedback,
SUM( IF( tbl_visit_info.activity_type = 2 ,1,0)) AS promise_order,
SUM( IF( tbl_visit_info.activity_type = 3 ,1,0)) AS stock,
SUM( IF( tbl_visit_info.activity_type = 6 ,1,0)) AS payment
FROM tbl_visit_info,tbl_retailer
where tbl_visit_info.retailer_id=tbl_retailer.retailer_id
and tbl_visit_info.visitor_id='".$_GET["sr_id"]."'
group by visitor_id,retailer_id having date_format(date, '%Y-%m-%d') BETWEEN
'".$_GET["start_date"]."' AND '".$_GET["end_date"]."'"
This query is not giving any result when I am writing code in PHP.