gerkintrigg Posted December 4, 2006 Share Posted December 4, 2006 Hi!I'm trying to work out how to use a switch statement to make a left join in a mysql query.Most of it works except if I choose the option to select all members that have not yet made a purchase.Could someone please have a look through this code and let me know what I'm doing wrong? thanks.This is the part that I'm having trouble with[code]switch ($_REQUEST['who']) {case "6months": $who="&&(timestamp>=(time()-2678400))"; $title_who='Customers From The Last 6 Months'; break;case "never":// this needs changing!! $who=" LEFT JOIN memberON member.userid=orders.user_id"; $title_who='Members who\'ve never bought anything'; break; [/code]then once i close the tag correctly I use this to execute the query:[code]mysql_query("SELECT member.Email FROM member, orders WHERE (member.Subscriber='Subscriber')".$who);[/code]Thanks for your help.Regards,Neil Link to comment https://forums.phpfreaks.com/topic/29400-mysql-query-in-a-switch-statement/ Share on other sites More sharing options...
Zane Posted December 4, 2006 Share Posted December 4, 2006 well I think a join goes before a WHERE clause anyway so your method wouldn't work right....I think not too certainbut this might work for members who haven't bought anythingSELECT member.Email FROM member, orders LEFT JOIN memberON member.userid=orders.user_idWHERE (member.Subscriber='Subscriber') ANDWHERE orders.users_id = null Link to comment https://forums.phpfreaks.com/topic/29400-mysql-query-in-a-switch-statement/#findComment-134883 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.