I want to search the row(venue_id) of a database with an array ($valueIDArray).
Is this the right way to do this?
$query = "SELECT * FROM venue_booking
WHERE venue_id = $valueIDArray";
I want to search the row(venue_id) of a database with an array ($valueIDArray).
Is this the right way to do this?
$query = "SELECT * FROM venue_booking
WHERE venue_id = $valueIDArray";
Your code is vulnerable to something called SQL injection; you generally prevent these attacks by using prepared statements.
If you mean, "Is this SQL statement syntactically valid?" yes, but not for an array. You need to use the IN statement; see Passing an array to a query using a WHERE clause.
$query = "SELECT * FROM venue_booking
WHERE venue_id IN (" . implode(", ", $valueIDArray) . ")";
Assuming $valueIDArray
values are numeric, implode
into a comma separated list and use the IN
clause:
$values = implode(',', $valueIDArray);
$query = "SELECT * FROM venue_booking WHERE venue_id IN ($values)";
If text etc. you need quotes:
$values = "'". implode("','", $valueIDArray) ."'";
First make a comma separated list of IDs and then use IN clause of SQL.
$comma_separated = implode(",", $valueIDArray);
$query = "SELECT * FROM venue_booking WHERE venue_id in ($comma_separated)";