shmideo Posted December 1, 2014 Share Posted December 1, 2014 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 Link to comment https://forums.phpfreaks.com/topic/292828-how-to-run-2-queries-based-on-input-value/ Share on other sites More sharing options...
Psycho Posted December 1, 2014 Share Posted December 1, 2014 Wouldn't the query without that condition include the records for both? There shouldn't be a need for two queries. You could actually add a dynamic field to the output to indicate which ones meet the like query if needed. Link to comment https://forums.phpfreaks.com/topic/292828-how-to-run-2-queries-based-on-input-value/#findComment-1498187 Share on other sites More sharing options...
shmideo Posted December 1, 2014 Author Share Posted December 1, 2014 No for some reason if that condition is present then no results are found for ones that don't require it. Can you give an example of a dynamic field to output please? Link to comment https://forums.phpfreaks.com/topic/292828-how-to-run-2-queries-based-on-input-value/#findComment-1498188 Share on other sites More sharing options...
Barand Posted December 1, 2014 Share Posted December 1, 2014 $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%' "; } Link to comment https://forums.phpfreaks.com/topic/292828-how-to-run-2-queries-based-on-input-value/#findComment-1498214 Share on other sites More sharing options...
shmideo Posted December 2, 2014 Author Share Posted December 2, 2014 Thank you Barand Link to comment https://forums.phpfreaks.com/topic/292828-how-to-run-2-queries-based-on-input-value/#findComment-1498275 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.