How do I tell MySQL to narrow it’s search by rows whose datetime collum has a date that falls within a specific time span? Like for example if I want to search for all rows with a datetime between January 1-31 2003
@evenstar7139authorJul 06.2006 — #But I want this page to pull up the current month's news post when somebody first goes to it. I would have to manually change that each month. Anyway to tell it to look for the current month?
@bokehJul 06.2006 — #Try to ask the question you want to ask right from the start. If you want it dynamic it would be helpful if you mentioned this. You should be able to do it like this but I didnt test it.
[CODE]WHERE MONTH($date_column) = MONTH(CURDATE()) AND YEAR($date_column) = YEAR(CURDATE())[/CODE]
@evenstar7139authorJul 07.2006 — #Okay and if it doesn't find anything for the current month, how can I tell it to keep going back by one month until it does?
@bokehJul 08.2006 — #So that it is dynamic and can be used easier, you can just set these to vars each time.[code=php]$tablename = 'table'; $date_column = 'date';[/code][/QUOTE]That's right! I can just copy and paste this query into another script and dont need to edit it at all even if the table and column names of the other script are completely different. Also there is less chance someone will "break" the code when editing it.