I wanna search for a certain value inside a JSON array but I only get an error message.
For example I wanna search for a certain country inside the JSON array and select only the user_id
of the user if the country id contained in the array.
I tried using JSON_CONTAINS
:
<?php
$query = "SELECT user_id FROM user
WHERE JSON_CONTAINS(user_info, 'us', '$.country')";
$row = mysqli_query($conn, $query) or die("Error: ".mysqli_error($conn));;
while($results = mysqli_fetch_array($row )){
echo $results['user_id']."<br>";
}
?>
My Database Table "user"
|user_id|username|user_info
| 1| xxx|{"language":["en","fr"],"country":["us"]}
| 2| xxx|{"language":["de"],"country":["au"]}
| 3| xxx|{"language":["ja"],"country":["us","jp"]}
My error message
Error: Invalid JSON text in argument 2 to function json_contains: "Invalid value." at position 0.