Welcome Guest, Not a member yet? Register   Sign In
Help with query structure, upcoming events and birthdays (two separate tables)
#11

[eluser]omick[/eluser]
lol... Big Grin i missed that...

just replace the "AND birth_date..." part in the where clause with:

AND DATE_FORMAT(birth_date, '%m%d') BETWEEN DATE_FORMAT(NOW(), '%m%d') AND DATE_FORMAT(DATE_ADD(NOW(), INTERVAL 1 WEEK), '%m%d') ...
#12

[eluser]JamieBarton[/eluser]
Ignore
#13

[eluser]JamieBarton[/eluser]
Ignore that, it was because of the single quotes.

I replaced all of that and now get the following

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

(SELECT id as id, start_time as date, title as name, '' as last_name, 'event' as type FROM events WHERE family_id = 1 AND start_time BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 1 WEEK)) UNION (SELECT user_id as id, birth_date as date, first_name as name, last_name as last_name, 'birthday' as type FROM users WHERE family_id = 1 AND DATE_FORMAT(birth_date, '%m%d') BETWEEN DATE_FORMAT(NOW(), '%m%d') AND DATE_FORMAT(DATE_ADD(NOW(), INTERVAL 1 WEEK), '%m%d') ORDER BY date LIMIT 5
#14

[eluser]JamieBarton[/eluser]
Nevermind! It appears it was missing a a curly bracket at the end.

Hopefully this is working properly, I'll report back if not! haha

Thanks again to everyone for their hard effort.
#15

[eluser]omick[/eluser]
hmmm... sorry... did you copy and paste the code? maybe some smart quotes problem... i should have place it in a code block...

Code:
AND DATE_FORMAT(birth_date, '%m%d')  BETWEEN DATE_FORMAT(NOW(), '%m%d') AND DATE_FORMAT(DATE_ADD(NOW(), INTERVAL 1 WEEK), '%m%d')
#16

[eluser]JamieBarton[/eluser]
Thanks, it's missing a bracket at the end, just incase anybody reads this thread in future.

Welcome to the forums!




Theme © iAndrew 2016 - Forum software by © MyBB