I have to create a web service in my application to pull data from a MySQL database using PHP. I don't know if what I want to do will work or not as I am new to PHP. Here is the code:
$queryString = "SELECT uniqueID, address FROM main WHERE (state = ?) AND (propType IN (?)";
$stmt = mysqli_prepare($this->connection, $queryString);
mysqli_stmt_bind_param($stmt, 'ss', $itemst, $itempt);
mysqli_stmt_execute($stmt);
My question has to do with the binding statement for the propType column of my database. In my application, there are like 8 different property types that a user can click a checkbox to search. What I would like to do is to stitch the strings together into one value represented above by $itempt, and just bind this single string to the SQL statement, but I don't know if I can do this???
If I can't, then I have to do something like the following:
$queryString = "SELECT uniqueID, address FROM main WHERE (state = ?) AND (propType IN (?,?,?,?,?,?,?,?)";
This could get complicated in the binding expression because I would have to test which property types were selected and come up with a variety of different queries/binding expressions, which would be laborious.
So my question is, with an "IN" clause, can I stitch all of the string values into a single comma-separated string, and then just bind this single value to my query, or do I have to pass a separate variable for each possible value and bind to them individually?
Thanks for any insight!