Jump to content

Mysql query in a switch statement


gerkintrigg

Recommended Posts

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 member
ON 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

well I think a join goes before a WHERE clause anyway so your method wouldn't work right....I think not too certain

but this might work for members who haven't bought anything

SELECT member.Email FROM member, orders
LEFT JOIN member
ON member.userid=orders.user_id
WHERE (member.Subscriber='Subscriber') AND
WHERE orders.users_id = null

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.