gpt4 book ai didi

php - 通过 PHP 在 phpMyAdmin 列中回显 json 数组

转载 作者:行者123 更新时间:2023-11-28 23:19:56 25 4
gpt4 key购买 nike

你好,我有这样的 JSON 行:

//THis is one of My Rows
[{"id":"26","answer":[{"option":"3","text":"HIGH"}],"type":"a"},
{"id":"30","answer":[{"option":"3","text":"LOW"}],"type":"b"},
{"id":"31","answer":[{"option":"3","text":"LOW"}],"type":"c"},
{"id":"32","answer":[{"option":"3","text":"HIGH"}],"type":"d"},
{"id":"33","answer":[{"option":"3","text":"HIGH"}],"type":"e"},
{"id":"34","answer":[{"option":"3","text":"HIGH"}],"type":"f"},
{"id":"40","answer":["Number 3"],"type":"g"}]

如何回显 id answer type,
db Name: array Table Name: user_survey_start JSON row Name: survey_answers, 这是我的代码:

    <?php
$con=mysqli_connect("localhost","root","","array");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

// $sql="SELECT survey_answers->"$.id" AS `twitter` FROM user_survey_start";
$sql="SELECT survey_answers FROM user_survey_start";


if ($result=mysqli_query($con,$sql))
{
// Fetch one and one row
while ($row=mysqli_fetch_row($result))
{
printf ("%s \n",$row[0]);
}
// Free result set
mysqli_free_result($result);
}

mysqli_close($con);
?>

最佳答案

您可以使用 json_decode() 函数将您的 json 转换为 php array()。之后,您可以根据需要迭代所有数据。

关于php - 通过 PHP 在 phpMyAdmin 列中回显 json 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42173353/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com