【问题标题】:echo json array in a phpMyAdmin Column VIA PHP在 phpMyAdmin 列中回显 json 数组 VIA PHP
【发布时间】: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);
    ?> 

【问题讨论】:

  • 问题是什么?同样对于 jsonNumber 3 中的最后一行将变为字符串
  • 我喜欢连接到我的表格列,并自动回显 json 行,但不知道我该怎么做,是的,我也喜欢修复那个字符串。谢谢
  • 您是否将 json 存储在列名`survey_answers` 中。
  • 是的,是的,我的专栏名称是 survey_answers,我需要将我的 json 对象分成 3 部分,分三列,可以吗?

标签: php mysql json


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    首先我需要选择我的主键

    $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>";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-22
      相关资源
      最近更新 更多