mb1 Posted May 29, 2011 Share Posted May 29, 2011 Hi, I am querying events for "today". So I have this code: $query3 ="SELECT * FROM `mb_foursquare`.`eventsbydate` WHERE `mb_foursquare`.`eventsbydate`.`datetime1` BETWEEN DATE_ADD(CURDATE(), INTERVAL -1 DAY) AND DATE_ADD(CURDATE(), INTERVAL 2 DAY)"; It works ok (if there is a better way to do this, feel free to let me know). But then I also need to pull data from a different table. So I added the other query but somehow it is triggering an error. Not sure what could be wrong, could you please help me? Here is the code that's triggering an error: $query3 ="SELECT * FROM `mb_foursquare`.`eventsbydate` WHERE `mb_foursquare`.`eventsbydate`.`datetime1` BETWEEN DATE_ADD(CURDATE(), INTERVAL -1 DAY) AND DATE_ADD(CURDATE(), INTERVAL 2 DAY), `mb_foursquare`.`venues` WHERE eventsbydate.v_id = venues.v_id"; Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/237784-querying-events-from-mysql-db-in-2-tables/ Share on other sites More sharing options...
tbare Posted May 29, 2011 Share Posted May 29, 2011 your second query has 2 WHERE statements... if you need to WHEREs, use WHERE a AND b... Quote Link to comment https://forums.phpfreaks.com/topic/237784-querying-events-from-mysql-db-in-2-tables/#findComment-1221914 Share on other sites More sharing options...
mb1 Posted May 29, 2011 Author Share Posted May 29, 2011 Thank you. That's only because i am querying 2 tables. I have this on one side: `mb_foursquare`.`eventsbydate` WHERE `mb_foursquare`.`eventsbydate`.`datetime1` BETWEEN DATE_ADD(CURDATE(), INTERVAL -1 DAY) AND DATE_ADD(CURDATE(), INTERVAL 2 DAY) And this on the other side: `mb_foursquare`.`venues` WHERE eventsbydate.v_id = venues.v_id Quote Link to comment https://forums.phpfreaks.com/topic/237784-querying-events-from-mysql-db-in-2-tables/#findComment-1221917 Share on other sites More sharing options...
tbare Posted May 29, 2011 Share Posted May 29, 2011 Look into a LEFT JOIN. I'm not exactly sure what you're looking to do, but here's an example of a left join: SELECT column_name(s) FROM table_name1 LEFT JOIN table_name2 ON table_name1.column_name=table_name2.column_name Quote Link to comment https://forums.phpfreaks.com/topic/237784-querying-events-from-mysql-db-in-2-tables/#findComment-1221920 Share on other sites More sharing options...
mb1 Posted May 29, 2011 Author Share Posted May 29, 2011 Thank you again. Let me be a little more specific about what i want to do: I am selecting from my event table (eventsbydate) all the events that are happening today. Then I am also pulling data on all the venues from a different table (venues). I tried this and it is still triggering an error... SELECT * FROM `mb_foursquare`.`eventsbydate` WHERE `mb_foursquare`.`eventsbydate`.`datetime1` BETWEEN DATE_ADD(CURDATE(), INTERVAL -1 DAY) AND DATE_ADD(CURDATE(), INTERVAL 2 DAY) LEFT JOIN `mb_foursquare`.`venues` ON eventsbydate.v_id = venues.v_id Any idea what the issue could be? Quote Link to comment https://forums.phpfreaks.com/topic/237784-querying-events-from-mysql-db-in-2-tables/#findComment-1221927 Share on other sites More sharing options...
tbare Posted May 31, 2011 Share Posted May 31, 2011 sorry i didn't reply back - long weekend - but not long enough to do too much on the computer. I'll look a bit more into it, and get back to ya today. (unless someone else chimes in, too). T Quote Link to comment https://forums.phpfreaks.com/topic/237784-querying-events-from-mysql-db-in-2-tables/#findComment-1222869 Share on other sites More sharing options...
mb1 Posted May 31, 2011 Author Share Posted May 31, 2011 Thank you. Actually, I figured it out! SELECT * FROM `mb_foursquare`.`eventsbydate`, `mb_foursquare`.`venues` WHERE DATE(datetime1) = DATE(CURDATE()) AND eventsbydate.v_id = venues.v_id I had to put the FROM table 1, table 2 at the very beginning. and attach the WHENs with an AND. Quote Link to comment https://forums.phpfreaks.com/topic/237784-querying-events-from-mysql-db-in-2-tables/#findComment-1222874 Share on other sites More sharing options...
tbare Posted May 31, 2011 Share Posted May 31, 2011 great! glad you got it working! Good luck on the rest of your project! Quote Link to comment https://forums.phpfreaks.com/topic/237784-querying-events-from-mysql-db-in-2-tables/#findComment-1222878 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.