MySQL Conditional Select -


i've been trying night following query work:

select user.username, user.email, user.id, user.last_mail, us.24hr wine_users user, wine_subscriptions sub, wine_user_settings user.id = sub.user_id , us.id = user.id , sub.wine1 = 'yes' , user.receive_mail = 'yes' , if(24hr = 'yes') user.last_mail >= date_sub (user.last_mail interval 1 day) 

basically, have 3 tables, containing username (wine_users), subscriptions (wine_subscriptions) , user settings(user_settings)

what want select users have either selected no in us.24hr or have selected yes in us.24hr (stored enum 'yes' 'no' in us.24hr) , have not received e-mail in last 24 hours (this stored timestamp in user.lastmail)

any stop me tearing out own brain through left nostril! :)

thanks :)

seb


wow! guys great! :) tried of suggestions, return following error:

1064 - have error in sql syntax; check manual corresponds mysql server version right syntax use near 'interval 1 day))) limit 0, 30' @ line 8

i'm guessing it's got date_sub command not liking timestamp format of user.last_mail field... correct, , if how handle this?

for clarity, script part of page gets fired chron every hour i've done me & few friends.
checks tesco wines availability of "mystery wine pack" (because web design better cheap wine!)
if available (which happens once week or so) e-mails users database either has 24hr set no (ie e-mails them every hour while product available) or has 24hr set yes , hasn't received e-mail in last 24 hours
(hence last_mail field, records timestamp when last e-mail sent)

really appreciate responses!

seb :)

see if trick.

select user.username, user.email, user.id, user.last_mail, us.24hr wine_users user, wine_subscriptions sub, wine_user_settings user.id = sub.user_id , us.id = user.id , sub.wine1 = 'yes' , user.receive_mail = 'yes' , ( (24hr = 'yes' , user.last_mail >= date_sub (user.last_mail interval 1 day)) or 24hr='no') 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -