Why is this working:
$sql_query = "SELECT * FROM Content WHERE id IN (1,5,7,9)";
But this isn’t:
$array_values = "1,5,7,9"; $sql_query = "SELECT * FROM Content WHERE id IN ('$array_values')";
I want to select data from the database based on the integers in the $array_values string. How can I do it?
Answer
because there are `
s in your code here
$sql_query = "SELECT * FROM Content WHERE id IN ('$array_values')";
use :
$sql_query = "SELECT * FROM Content WHERE id IN ( $array_values )";
or
$sql_query = "SELECT * FROM Content WHERE id IN (".$array_values.")";