Easy way to generate report from 8 different parameters in php mysql [on hold]

161
April 12, 2018, at 4:13 PM

I want to run report from 8 different combination. Each input can be empty or can be filled with data. Thus to get results from 8 input parameters, i need to write 256 ifelse condition in where clause of mysql query in php.

Attaching screenshot for input parameters & code also.

Code as follows: Here you can see i have added 50+ ifelse condition, will require to add 200 more...

$sql="select profile_distributer.did,profile_distributer.dtype,distributer_type.d_type,profile_distributer.dis_bname, profile_distributer.dis_cname, profile_distributer.dis_email, profile_distributer.date, profile_distributer.reg_by from profile_distributer inner join distributer_type on profile_distributer.dtype=distributer_type.id ";
if(!empty($from) && !empty($to) && !empty($sales) && !empty($country) && !empty($state) && !empty($city)  && !empty($product) && !empty($type))
{
    $sql.="where profile_distributer.date between '$from' and '$to' and profile_distributer.reg_by='$sales' and profile_distributer.dis_country='$country' and  profile_distributer.dis_state='$state' and  profile_distributer.dis_city='$city' and profile_distributer.dtype='$type'  and profile_distributer.dis_product='$product' order by profile_distributer.did desc";
}
else if(empty($from) && empty($to) && empty($sales) && empty($country) && empty($state) && empty($city) && empty($product) && empty($type))
{
    $sql.=" order by profile_distributer.did DESC ";
}
else if(!empty($from) && !empty($to) && empty($sales) && empty($country) && empty($state) && empty($city)  && empty($product) && empty($type))
{
    $sql.=" where profile_distributer.date between '$from' and '$to' order by profile_distributer.did DESC ";
}
else if(!empty($from) && !empty($to) && !empty($sales) && empty($country) && empty($state) && empty($city)  && empty($product) && empty($type))
{
    $sql.="where profile_distributer.date between '$from' and '$to' and profile_distributer.reg_by='$sales' order by profile_distributer.did DESC ";
}
else if(!empty($from) && !empty($to) && !empty($sales) && !empty($country) && empty($state) && empty($city)  && empty($product) && empty($type))
{
    $sql.="where profile_distributer.date between '$from' and '$to' and profile_distributer.reg_by='$sales' and profile_distributer.dis_country='$country' order by profile_distributer.did DESC ";
}
else if(!empty($from) && !empty($to) && !empty($sales) && !empty($country) && !empty($state) && empty($city)  && empty($product) && empty($type))
{
    $sql.="where profile_distributer.date between '$from' and '$to' and profile_distributer.reg_by='$sales' and profile_distributer.dis_country='$country' and  profile_distributer.dis_state='$state' order by profile_distributer.did DESC ";
}

I want to know is there any easy way of doing the same?

Rent Charter Buses Company
READ ALSO
“Class App\Repositories\TodoInterface does not exist” Laravel 5.5

“Class App\Repositories\TodoInterface does not exist” Laravel 5.5

I'm trying to implement repositories in my application structure

245
Upload progress bar using session.upload_progress

Upload progress bar using session.upload_progress

Implemented progress bar using sessionupload_progress, Worked fine for some days

197
How can I post a form via PHP Curl and By Pass Google Recaptcha [on hold]

How can I post a form via PHP Curl and By Pass Google Recaptcha [on hold]

How can I post a form via PHP Curl and By Pass Google Recaptcha

152
Upload file not working through Facebook app browser

Upload file not working through Facebook app browser

The Upload file button is working fine on Chrome, Safari, Mozilla or in any native browser on mobileWhen I shared the link to Facebook and user click on the link, the page opens in the Facebook app browser but Upload file button doesn’t work

148