chemicaluser Posted March 11, 2011 Share Posted March 11, 2011 Hope someone can help. i am trying to search between two date ranges but am not sure how to add it to the rest of my query. this is my original query which works fine .. it does not have the start and end date part $query = "SELECT * FROM table WHERE hdt1 like '%$hdt1_search%' and hdt2 like '%$hdt2_search%' and hdt3 like '%$hdt3_search%' and dateadd like '$dateadd_search'"; this is the start date to end date search, ...it works ok when it is the only thing in the query $query = "SELECT * FROM table WHERE dateadd >= '$start_date' AND dateadd <= '$end_date'"; BUT, when i try to put it all together the only two fields that get search are the start date to end date search. ... $query = "SELECT * FROM table WHERE hdt1 like '%$hdt1_search%' and hdt2 like '%$hdt2_search%' and hdt3 like '%$hdt3_search%' and dateadd like '$dateadd_search' and dateadd >= '$start_date' AND dateadd <= '$end_date' "; what am i doing wrong???? Quote Link to comment https://forums.phpfreaks.com/topic/230313-mysql-query-problem/ Share on other sites More sharing options...
HuggieBear Posted March 11, 2011 Share Posted March 11, 2011 Try parentheses around the date range $query = "SELECT * FROM table WHERE hdt1 like '%$hdt1_search%' and hdt2 like '%$hdt2_search%' and hdt3 like '%$hdt3_search%' and dateadd like '$dateadd_search' and (dateadd >= '$start_date' AND dateadd <= '$end_date') "; Quote Link to comment https://forums.phpfreaks.com/topic/230313-mysql-query-problem/#findComment-1186094 Share on other sites More sharing options...
PFMaBiSmAd Posted March 11, 2011 Share Posted March 11, 2011 There's nothing logically wrong with your complete query. If it didn't return the results you expected, either you didn't save the changed code or your didn't upload the changed file to your web server or the results you got where actually correct for the data you have and what you searched for. Quote Link to comment https://forums.phpfreaks.com/topic/230313-mysql-query-problem/#findComment-1186100 Share on other sites More sharing options...
chemicaluser Posted March 12, 2011 Author Share Posted March 12, 2011 I tried the parentheses but it is still not working.. once i add this part its the only part of the query that returns results ... dateadd >= '$start_date' AND dateadd <= '$end_date' and once i delete it ... the rest of the query works without problems ...i know that i am saving and uploading the right file because when i change the code i get different results Quote Link to comment https://forums.phpfreaks.com/topic/230313-mysql-query-problem/#findComment-1186550 Share on other sites More sharing options...
chemicaluser Posted March 12, 2011 Author Share Posted March 12, 2011 I tried the parentheses but it is still not working ... sort of once i add this part to the query it becomes mandatory to have dates entered in the start/end field during the search, otherwise it returns no results dateadd >= '$start_date' AND dateadd <= '$end_date' but once i delete it ... the rest of the query works without problems ...i know that i am saving and uploading the right file because when i change the code i get different results Quote Link to comment https://forums.phpfreaks.com/topic/230313-mysql-query-problem/#findComment-1186551 Share on other sites More sharing options...
PFMaBiSmAd Posted March 12, 2011 Share Posted March 12, 2011 Unless you post exactly what you are putting in to the query (echo the $query variable in your code and post what it is), what your data is in your table that you expect the query to match, what result you are getting, what result you expect, and what your actual code is that is executing the query and retrieving and displaying the results, no one here can directly help you. You are expecting us to be able to guess based on "it is still not working" and "the rest of the query works without problems" what your code and data is, what you searched for, and what you saw in front of you that leads you to believe that something that you are doing worked or didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/230313-mysql-query-problem/#findComment-1186567 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.