Jump to content

[SOLVED] MySQL select statement help


patricio555

Recommended Posts

I am using a calendarix calendar on my band site and I found that I could create an "upcoming events" mini table listing events that match a specified category (ie "shows"). (I don't like their mini calendar - it just doesn't work for what I need - overcomplicated.)

 

In the calendar db, there is a table called calendar_events and in that table there are two columns "day" and "month" which are stored as integers. I have built a simple select statement and a loop to print the various records in a small table on the side of the page.

 

I am trying to figure out how to construct a query with a where clause that limits the entries to the events "greater than or equal to" today's date, and I am having no luck.

I have tried using the php function iDate with the format (dm) which should give me the day and month in integer format. What I cannot figure out is how to split the day and month into the select query (ie SELECT * FROM calendar_events WHERE day>= ? AND month>= ? AND category="2" ORDER BY date)

 

The question marks above are where I cannot figure out what to use. I tried using .iDate(d) and .iDate(m) in their place but this does not seem to work.

 

I am kind of a noob, but I know enough to get myself into trouble. I am hoping some kind soul will help me out on this one.

 

Thanks in advance.

Link to comment
Share on other sites

Thanks for your reply. While your idea didn't work, it did lead me to discover what was going wrong...now it's just a matter of figuring out how to fix it.

 

It doesn't work because I am comparing the "day" column against today's date. Thusly, if one show is on 5/22 and today is 4/30 then it will return no records because 22<30. (Though they'd be fine on the 1st!).

 

My idea is that if I could somehow get the yearday (0-365) from the month(int) and day(int) columns, then I could compare that against today's date using getdate(yday)....only problem is, I cannot figure out how to do this. I am pretty terrible at math.

 

Right now, it is set up to show all records >= current month, which is fine, except events don't expire when they have passed - they hang around til the end of the month. Not much wrong with that, but the proble is just buggin me! ;)

 

 

 

Link to comment
Share on other sites

GOT IT!

 

Here is the successful query for anyone interested:

 

$sql = "SELECT * FROM calendar_events

WHERE (day >= '" .date('j', time()) ."' AND month= '".date('n', time())."' and cat='2' ) OR

(cat='2' AND month > '".date('n', time())."') ORDER BY  month,day ASC

LIMIT 0 , 30";

 

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.