Jump to content

MySQL syntax problems?


another_php_newb

Recommended Posts

I have worked with M$ SQL, but I am now switching to MySQL.  Something I think should work is not, but I can not figure out why...

 

I am trying to build a calendar with SQL / PHP that displays historic events coming up for next 30 days as well as Month long and week long celebrations (like both July 4th 1776 and Gay Pride Month).

 

MySQL Server version:  5.1.52

 

 

SELECT Name, URL, startDate, endDate, annual, wholemonth,

monthname(startDate) as m1, monthname(endDate) as m2,

DATE_FORMAT(startDate, '%b %e') as md1,  DATE_FORMAT(endDate, '%b %e') as md2,

DATE_FORMAT(endDate, '%e') as d2, DATE_FORMAT(startDate, '%Y') as y1,

DATE_FORMAT(endDate, '%Y') as y2, dayofyear(startdate) as doy,

dayofyear(curdate()) as doyc

FROM Calendar 

where

(curdate() between startDate and endDate)

OR

(annual = 1 and wholemonth = 1 and month(startDate) = month(curdate()))

OR

(annual = 1) and (( doy - doyc)  % 365) < = 30 ) -- this line is causing the problem

 

Order by doy asc LIMIT 0, 30

 

My DB is set up with these cols: PID, startDate,endDate,Name,URL,annual,wholemonth

 

I know this is not normalized with the whole month tag, but I do not really care.  There will be at most ~1000 events in here, and it will be just easier to keep that flag.

 

What I want to do with the line that is causing an error is include events that are in the near future next 30 days (even if it is toward the end of December). 

 

 

 

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.