Hi all:
I am at loss as to how to bind parameters in this particular case. Maybe someone can help...
I have a form with 11 fields. These fields are going to a SQL SELECT query. All fields are optional and the more fields entered, the less results will appear as I am (mostly) using AND throughout the WHERE portion of the statement.
Here is the problem. If a field is not entered (as mentioned, all fields are optional) I do not want it to be read in the SQL QUERY. I do not want it in the WHERE portion as this will cause no records to appear. For example,
WHERE
player = ? AND
state = ? AND
eventDate = ? AND
sportCode = ? AND
prID = ? AND
listingDate = ? AND
discountAmount = ? AND
mailOrder = ? AND
big15 = ? AND
evID = ? AND
(team1 = ? OR
team2 = ? OR
team3 = ? OR
team4 = ? OR
team5 = ? OR
team6 = ? OR
team7 = ? OR
team8 = ? OR
team9 = ? OR
team10 = ? OR
team11 = ? OR
team12 = ? OR)
EventDate >= CURDATE() AND
StartDate <= CURDATE() AND
hold IS NULL
If a search is made with the above for STATE only and 'New York' is chosen, instead of having every event in New York appear, nothing will appear. What I would really need is for the WHERE to become
WHERE
state = ?
EventDate >= CURDATE() AND
StartDate <= CURDATE() AND
hold IS NULL
I can do this. I can build a WHERE variable using ISSET and only include the fields that are set. So this brings me back to my original issue, binding the parameters. How do I change:
mysqli_stmt_bind_param($stmt, "ssssssssssssssssssssss",
to
mysqli_stmt_bind_param($stmt, "s",
on the fly?
Hope this makes sense!
Thanks