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 Quote 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. Quote 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? Quote 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...
Solution Barand Posted December 1, 2014 Solution 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%' "; } Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.