views:

19

answers:

2

In one page, it should show records that has the following selected month from the drop down menu and it is set in the ?month=March

So the query will do this

$sql = "SELECT * FROM schedule WHERE month = '" . Clean($_GET['month']) . "' AND finished='0' ORDER BY date ASC";

But it shows records that has a value of 2 in the finished column and I don't want the query to include this.

I've tried

$sql = "SELECT * FROM schedule WHERE month = '" . Clean($_GET['month']) . "' AND finished='0' OR finished = '1' OR finished = '3' ORDER BY date ASC";

But it shows records on different months when it shouldn't be.

So basically I want the record to exclude the records that has the value of 2 in the record that will not be shown in the page.

A: 

Your first query should do what you want. Rows with finished = '2' should not be returned.

Ignoring that there is an error in your second query that you probably should fix:

$sql = "SELECT * FROM schedule WHERE month = '" . Clean($_GET['month']) .
       "' AND (finished='0' OR finished = '1' OR finished = '3') ORDER BY date ASC";

The difference is parentheses around the OR clauses because AND binds more strongly than OR.

You could also achieve the same result more concisely using IN:

$sql = "SELECT * FROM schedule WHERE month = '" . Clean($_GET['month']) .
       "' AND finished IN ('0', '1', '3') ORDER BY date ASC";
Mark Byers
Wow, quick answer :) thanks for this, I used your second code
YouBook
A: 

AND finished='0' OR finished = '1' OR finished = '3'

to

AND finished != 2

or

AND (finished = 0 OR finished = 1 OR finished = 3)

Coronatus