I’m posting a JSONArray.toString() to a php file. The JSONArray contains a set of id values. I want to make a mysql query that only returns rows that have an id contained in the jsonarray. My method below isn’t working. Is there another way?
$jsonarray= $_POST["ids"];
$query = mysql_query("SELECT * FROM table WHERE id IN $jsonarray")or die(mysql_error());
It’d help if we had an example of the JSON array, however, you should decode the JSON array into a comma separated list to use with IN.
Also, you should be using mysqli or PDO_MySQL for new development:
Related Reading: