Samuel Meddows
Samuel Meddows

Reputation: 36712

MySQL select query

I have a simple MySQL query that selects all columns from the table based off two requirements.

`$dbSearchRecords = mysql_query("SELECT * FROM booking WHERE BookingID = '$JobNo_search' AND Date BETWEEN '$DateFrom_search' AND '$DateTo_search'" )`

I am trying to get the query to search either one or both of the requirements. WHERE BookingID = '$JobNo_search' AND Date BETWEEN '$DateFrom_search' AND '$DateTo_search'

At the moment all parameters need to be present to get a result and I need to be able to search just the BookinID or just the date range as well.

Cheers guys.

Upvotes: 0

Views: 82

Answers (1)

willdanceforfun
willdanceforfun

Reputation: 11240

What about...

$dbSearchRecords = mysql_query(

  "SELECT * FROM booking 
   WHERE BookingID = '$JobNo_search' 
   OR ( Date BETWEEN '$DateFrom_search' AND '$DateTo_search' ) 
   OR itemid = $itemID
   OR job_no = $job_no
   OR rego = $rego
  "

)

The OR works as AND/OR.

Upvotes: 1

Related Questions