你好,我有像这样的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);
?>
答案 0 :(得分:1)
你可以使用json_decode()函数将你的json转换成php array()。之后,您可以根据需要迭代所有数据。
答案 1 :(得分:0)
首先,我需要选择我的主键
$sql="SELECT `survey_answers`,us_id FROM `user_survey_start`";
然后将值放入ID
$id[] = $data['id'];
之后
$sql1="update user_survey_start set id2='$ids' where us_id=".$row[1];//run update sql
echo $sql1."<br>";