Jump to content

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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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