liamloveslearning Posted May 28, 2010 Share Posted May 28, 2010 Hi all, im trying to select all values from a database for x user where the date is from the last 7 days, im trying this query to no avail, could anybody please take a look? SELECT * FROM model_pictures WHERE user_id = colname AND model_pictures.user_picture_date > DATE_sub(model_pictures.user_picture_date, interval 7 DAY) Quote Link to comment https://forums.phpfreaks.com/topic/203198-select-all-where-last-7-days-from-variable/ Share on other sites More sharing options...
liamloveslearning Posted May 28, 2010 Author Share Posted May 28, 2010 In fact, I need a to make an if statement which says if user x has a record containing the upload date between today and the last 7 days, dont show form, To do this im triying to make a query which calls that data and my query is the above, Does this make sense? Quote Link to comment https://forums.phpfreaks.com/topic/203198-select-all-where-last-7-days-from-variable/#findComment-1064639 Share on other sites More sharing options...
liamloveslearning Posted May 28, 2010 Author Share Posted May 28, 2010 this seems to be working but its days in the future not SUB days? SELECT * FROM model_pictures WHERE user_id = colname AND model_pictures.user_picture_date > DATE_SUB(CURDATE(), INTERVAL 7 DAY) Quote Link to comment https://forums.phpfreaks.com/topic/203198-select-all-where-last-7-days-from-variable/#findComment-1064640 Share on other sites More sharing options...
liamloveslearning Posted May 28, 2010 Author Share Posted May 28, 2010 Ive just realised i need <= as opposed to equals too but it still doesnt seem to work? Quote Link to comment https://forums.phpfreaks.com/topic/203198-select-all-where-last-7-days-from-variable/#findComment-1064648 Share on other sites More sharing options...
waterssaz Posted May 28, 2010 Share Posted May 28, 2010 Use BETWEEN curdate and the date_sub even Quote Link to comment https://forums.phpfreaks.com/topic/203198-select-all-where-last-7-days-from-variable/#findComment-1064649 Share on other sites More sharing options...
liamloveslearning Posted May 28, 2010 Author Share Posted May 28, 2010 so... SELECT * FROM model_pictures WHERE user_id = colname AND BETWEEN curdate() AND model_pictures.user_picture_date (DAY(CURDATE()), interval 7 day) Quote Link to comment https://forums.phpfreaks.com/topic/203198-select-all-where-last-7-days-from-variable/#findComment-1064653 Share on other sites More sharing options...
liamloveslearning Posted May 28, 2010 Author Share Posted May 28, 2010 sorted! SELECT * FROM model_pictures WHERE user_id = colname AND model_pictures.user_picture_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND CURDATE() Quote Link to comment https://forums.phpfreaks.com/topic/203198-select-all-where-last-7-days-from-variable/#findComment-1064655 Share on other sites More sharing options...
waterssaz Posted May 28, 2010 Share Posted May 28, 2010 no like SELECT *FROM model_picturesWHERE user_id = colname AND model_pictures.user_picture_date BETWEEN BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 7 DAY ) AND CURDATE( ) Quote Link to comment https://forums.phpfreaks.com/topic/203198-select-all-where-last-7-days-from-variable/#findComment-1064656 Share on other sites More sharing options...
waterssaz Posted May 28, 2010 Share Posted May 28, 2010 beat me lol :-) But mine had extra BETWEEN typo as well Quote Link to comment https://forums.phpfreaks.com/topic/203198-select-all-where-last-7-days-from-variable/#findComment-1064657 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.