this is my php code:
<?php
//Creating a connection
$con = mysqli_connect("****","****","****","****");
$con->set_charset("utf8");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$strcode = $_GET["id"];
$sql = "Select movie_image from map_table2 where movie_image = '".$strcode."' ORDER BY id DESC LIMIT 1 ";
$result = mysqli_query($con ,$sql);
while ($row = mysqli_fetch_assoc($result)) {
$array[] = $row;
}
header('Content-Type: text/html; charset=utf-8');
echo json_encode($array, JSON_UNESCAPED_UNICODE );
mysqli_free_result($result);
mysqli_close($con);
?>
When I run the php, I get this data:
[{"movie_image":"231320166"}]
But I want to get this data:
231320166
What code should I use?
replace:
json_encode($array, JSON_UNESCAPED_UNICODE );
with:
echo $array[0]['movie_image'];
Use json_decode()
http://php.net/manual/en/function.json-decode.php
<?php
$json = '[{"movie_image":"231320166"}]';
$array = json_decode($json, true);
$image = $array[0]['movie_image'];
echo $image;
See it here https://3v4l.org/lrnL6
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.