1 reply [Last post]
arbel's picture
Offline
Bug FinderGetting busy with the Ubercode.
Joined: 08/12/2007
Juice: 331
Was this information Helpful?

Hi,

I need some assistance with an sql query for a module i'm working on...

in a table called bill_months, there are two fields: year, month. these represent when this record was created.

I need to select record from the last three months, how do I do this with the fields split?

Thanks

Idan

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: help with sql query

Honestly, I wouldn't split it up like that but store your times as timestamps (using PHP's time() function) in integer fields. That way you can do things like use PHP's strtotime() to create a timestamp for "3 months ago" and pull up any row in the database with a later timestamp.

If you just can't change it, you can always use IN() in your where clause, like:

pseudo-code, assuming you're storing month names:

SELECT * FROM {your_table} WHERE month IN ('January', 'December', 'November')

You'll have to write some code that creates the IN array... it turns out to be a bit more work than timestamps.