antonyfal Posted December 17, 2011 Share Posted December 17, 2011 Hi, Doing a Query SELECT * FROM table WHERE field BETWEEN low_number AND high_number If i have three rows with three numbers: IE: 27, 50, 80. and i run the query above, it returns a result of: 27 and 50. How can i get it to return a result of: 27,50, and 80.?? WHY: age range search: i want to return an age range of people = and between the age of say: 20 and 70 but i want to include the 20 and 70. How can i do this? Quote Link to comment https://forums.phpfreaks.com/topic/253367-php-mysql-between-function-query/ Share on other sites More sharing options...
paparts Posted December 17, 2011 Share Posted December 17, 2011 select * from table where age >= 20 and age <=70; Quote Link to comment https://forums.phpfreaks.com/topic/253367-php-mysql-between-function-query/#findComment-1298794 Share on other sites More sharing options...
PFMaBiSmAd Posted December 17, 2011 Share Posted December 17, 2011 Unless a person is dead, their age is not a constant number. It changes once a year on their birthday. You need to store the date of birth and then to find age ranges, perform a date comparison that corresponds to the correct birthday date range calculated relative to the current date. Quote Link to comment https://forums.phpfreaks.com/topic/253367-php-mysql-between-function-query/#findComment-1298797 Share on other sites More sharing options...
antonyfal Posted December 17, 2011 Author Share Posted December 17, 2011 Thanks Insane. Works well. I dont know why i had the BETWEEN function stuck in my head. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/253367-php-mysql-between-function-query/#findComment-1298824 Share on other sites More sharing options...
Pikachu2000 Posted December 17, 2011 Share Posted December 17, 2011 I agree with PFMaBiSmAd, but a BETWEEN query should work fine if you insist on proceeding with what you have. If you read the manual entry, you'll see that the values used in the BETWEEN comparison are inclusive. Quote Link to comment https://forums.phpfreaks.com/topic/253367-php-mysql-between-function-query/#findComment-1298842 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.