0

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?

HavanaSun
  • 446
  • 3
  • 12
  • 39

1 Answers1

1

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.")";
Alaa Mimo
  • 36
  • 3