yogibear Posted August 29, 2008 Share Posted August 29, 2008 Hi Is it possible to use LIKE, AND & BETWEEN in the same sql statement? Something like: $sql = "SELECT * FROM payment WHERE Name LIKE '%$Name%' AND Date BETWEEN LIKE '$new_date1' AND LIKE '$new_date2' LIMIT $offset, $rowsperpage"; Best wishes Yogi Quote Link to comment https://forums.phpfreaks.com/topic/121894-solved-like-and-between/ Share on other sites More sharing options...
akitchin Posted August 29, 2008 Share Posted August 29, 2008 no, it isn't. LIKE implies ambiguity in the matches, how is MySQL supposed to know when a field is BETWEEN those? is there a reason why you're trying to do this? Quote Link to comment https://forums.phpfreaks.com/topic/121894-solved-like-and-between/#findComment-628932 Share on other sites More sharing options...
yogibear Posted August 30, 2008 Author Share Posted August 30, 2008 Hi Thanks for your reply On one of my other pages the user can enter information to search the database in several different textboxes and some drop down menus. For that page I use LIKE and if one of the textboxes hasn’t had information entered it won’t only return the results that have an empty field. This is the code I use for that page: $result = mysql_query("SELECT * FROM Record WHERE Date_of_flight LIKE '%$new_date%' AND Pilot_name LIKE '%$Pilot_name%' AND Take_off_airfield LIKE '%$Take_off_airfield%' AND Arrival_field LIKE '%$Arrival_field%' AND Payment_method LIKE '%$Payment_method%'"); For this new page I want to be able to search the database in the same way but be able to search between two dates as well, and if the two dates haven’t been entered it doesn’t return records that have an empty date field. Best wishes Yogi Quote Link to comment https://forums.phpfreaks.com/topic/121894-solved-like-and-between/#findComment-629648 Share on other sites More sharing options...
QuietWhistler Posted August 30, 2008 Share Posted August 30, 2008 Why don't you use the following statement then? <?php $sql = "SELECT * FROM payment WHERE Name LIKE '%$Name%' AND ( Date > '$new_date1' AND Date < '$new_date2' ) LIMIT $offset, $rowsperpage"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/121894-solved-like-and-between/#findComment-629863 Share on other sites More sharing options...
yogibear Posted August 31, 2008 Author Share Posted August 31, 2008 Hi Thanks for your help But I have now fixed the problem using a series of if statements, it may not be perfect but it gets the job done. I will save your code as it is a much more efficient way of doing what I was trying to accomplish. Best wishes yogi Quote Link to comment https://forums.phpfreaks.com/topic/121894-solved-like-and-between/#findComment-630264 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.