$result = mysql_query("SELECT * FROM patterns WHERE YEARWEEK(datetxt = YEARWEEK(CURDATE())) ORDER BY dsptxt");
It doesn't error out, but doesn't display any results either and I have a test db it's connecting to where I have put 3 records in with the date being todays date.
Glad to be of help! Hehehe.
The initial problem was here: $past = date('Y-m-d', strtotime('-1 weeks');. You're simply missing the ending ); however, using the functions within the query directly is IMO a much better option.
Glad to be of help! Hehehe.
The initial problem was here: $past = date('Y-m-d', strtotime('-1 weeks');. You're simply missing the ending ); however, using the functions within the query directly is IMO a much better option.
Thanks! It always seems to be a missing element somewhere. Now, I do like the code I did end up getting working better, the question remains if I can use that code to display items in the database added 2 weeks ago, and 3 weeks ago.
It's basically for a "Recently Added" type page that shows "New this week", "New Last Week", and "New 3 Weeks Ago".
The 1st bit of code works, but when you get to the 2 and 3 weeks ago, it also displays everything from this week as well. Would like to isolate the query to just those items from 2 and 3 weeks in the past, if possible.
That's because of the operator in use. If you want to do that using PHP code, you need to select a date that is BETWEEN two other dates (one three weeks ago and one two weeks ago). Otherwise you get everything from three weeks ago to current.
MySQL can do that too, just use the date_add/date_sub or the overloads of the -/+ operators: WHERE datetxt BETWEEN CURDATE() - INTERVAL 3 WEEK AND CURDATE() - INTERVAL 2 WEEK looks like it would work.
YEARWEEK would work, except you need to check for the YEAR and you need to check when the current week is <= the provided week in the year (since then you have to go back and check last years records). This is easier to do if you manipulate the field itself, but you will slow down the query in doing so. So I think using BETWEEN is a better option.
Your missing the interval on the until date. That is the same as using datetxt >= CURDATE() - INTERVAL 2 WEEK. If you just want records from two weeks ago, but not from the current week, then you need to add the second interval condition.
Your missing the interval on the until date. That is the same as using datetxt >= CURDATE() - INTERVAL 2 WEEK. If you just want records from two weeks ago, but not from the current week, then you need to add the second interval condition.
Ok, I understand what you are saying but at the same time I don't. At least, when it comes to how to write the query for it, I'm not sure what I need to do and where I need to do it. Heading back to google for some help on this query.