【发布时间】:2017-02-11 07:13:43
【问题描述】:
你好,我有这样的 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
Number 3中的最后一行将变为字符串 -
我喜欢连接到我的表格列,并自动回显 json 行,但不知道我该怎么做,是的,我也喜欢修复那个字符串。谢谢
-
您是否将 json 存储在列名`survey_answers` 中。
-
是的,是的,我的专栏名称是 survey_answers,我需要将我的 json 对象分成 3 部分,分三列,可以吗?