Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > mysql question

mysql question
Thread Tools
Mac Elite
Join Date: Dec 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Aug 29, 2003, 06:25 PM
 
I am working with php and mysql.
I have two columns set up in a database. One is year, the second one is month. For simplicity let's say that they are both integer numbers.

I want to select everything from the database that is for this year and beyond, starting from the current month.

This is what I have so far:

today_year=date("Y");
today_month=date("m");
$query="select * from $db where year>=$today_year and $month=$today_month";

how can I tell the database, that I want everything from the current month in the present year, plus everything for years after?

Thanks,


t
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Aug 29, 2003, 08:13 PM
 
Why would you store month and year as integers? Store dates as dates, and you get lots of nice query functions that would require lots of logic otherwise.
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
Occasionally Useful
Join Date: Jun 2001
Location: Liverpool, UK
Status: Offline
Reply With Quote
Aug 30, 2003, 07:23 AM
 
Web Developer
For discussion of languages, databases, or anything else related to Web deployment
eh?

oh, and what Arkham_c said, about dates
"Have sharp knives. Be creative. Cook to music" ~ maxelson
     
Professional Poster
Join Date: Dec 2001
Location: somewhere
Status: Offline
Reply With Quote
Aug 31, 2003, 07:00 AM
 
Originally posted by t_hah:
I am working with php and mysql.
I have two columns set up in a database. One is year, the second one is month. For simplicity let's say that they are both integer numbers.

I want to select everything from the database that is for this year and beyond, starting from the current month.

This is what I have so far:

today_year=date("Y");
today_month=date("m");
$query="select * from $db where year>=$today_year and $month=$today_month";

how can I tell the database, that I want everything from the current month in the present year, plus everything for years after?

Thanks,


t
SELECT * FROM [table] WHERE (year = 2003 AND month >= 9) or year > 2003

But, you really should just store dates as actual dates. That way, you can just say:

SELECT * FROM [table] WHERE order_date >= '2003-09-01'
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 10:16 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2