0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.