Jump to content

MySql -- AND / OR questions


snowdog

Recommended Posts

I have an sql query and I need some help.

 

Here is my query

 

        $query = "SELECT * FROM call_reminder WHERE date >= '$todays_date' AND date >= '$start_date' AND date <= '$end_date' AND call = 'Bonus Call' AND level = 1 AND member_group = '$member_group' OR member_group = 'all' ORDER BY date ASC";

 

basically if it was a math equation I would put brackets here to force it to be:

 

        $query = "SELECT * FROM call_reminder WHERE date >= '$todays_date' AND date >= '$start_date' AND date <= '$end_date' AND call = 'Bonus Call' AND level = 1 AND (member_group = '$member_group' OR member_group = 'all') ORDER BY date ASC";

 

It is not doing the sql the way I want it to. I want it to act like a math equation in the brackets. DOes anyone know how to make this happen? I know there is lots of AND's but I need the OR part to work also incase there is twp Bonus calls in the same time frame (say two months) and only one group is supposed to see one of them(ie: oriebtation call for a new group), then all groups could see the 2nd one.

 

Thanks in advance.

 

Snowdog

Link to comment
https://forums.phpfreaks.com/topic/49008-mysql-and-or-questions/
Share on other sites

I think for something like this you would need to use UNION

 

$query = "(SELECT * FROM call_reminder WHERE date >= '$todays_date' AND date >= '$start_date' AND date <= '$end_date' AND call = 'Bonus Call' AND level = 1 AND member_group = '$member_group') UNION (SELECT * FROM call_reminder WHERE date >= '$todays_date' AND date >= '$start_date' AND date <= '$end_date' AND call = 'Bonus Call' AND level = 1 AND member_group = 'all') ORDER BY date ASC";

 

Also, if you have any trouble with the date fieldname, put backticks around date eg: `date` (MYSQL Reserved Words)

Thanks I will give that a try, I have never heard of that before. I just figured there was something simpole I was missing. I am self taught and it ias hard for me to sometimes explain or what I am looking for because I dont know what I am searching for. Thanks again

 

Snowdog

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.