Jump to content

How to run 2 queries based on input value


shmideo

Recommended Posts

Hi

 

I have a form that has a drop-down with a few to choose from, unfortunately I don't get results for some due to the query involved.

Some need the AND channel LIKE '%$channel%'"; and some don't and therefore will not get desired results. So I would like to run two queries one with and one without.

 

$query = "SELECT * FROM asterisk_cdr WHERE calldate BETWEEN '$calldate' AND '$calldate2' AND clid LIKE '%$clid%' AND channel LIKE '%$channel%'";

 

Thanks

 


$query = "SELECT * FROM asterisk_cdr WHERE calldate BETWEEN '$calldate' AND '$calldate2' AND clid LIKE '%$clid%'";

if (!empty($_GET['channel'])) {
$channel = $mysqli->real_escape_string($_GET['channel']);
$query .= " AND channel LIKE '%$channel%' ";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.