2

Hello I have JSON rows like This:

//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"}]

How Can I echo id answer type,
and db Name: array Table Name: user_survey_start JSON row Name: survey_answers, This is my code:

    <?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);
    ?> 
4
  • And what is the issue? Also for last line in jsonNumber 3 will become string Commented Feb 11, 2017 at 7:19
  • I Like to Connect to my Table Column, And echo json rows Automaticaly, But Don't Know how can i do that, Yes yes I like to fix That String too. Thank you Commented Feb 11, 2017 at 7:22
  • are you storing json in column name ` survey_answers` . Commented Feb 13, 2017 at 10:40
  • yes yes my column Name is survey_answers, i need make my json object to 3 part, in three column, can i? Commented Feb 15, 2017 at 6:24

2 Answers 2

1

you can use json_decode() function to convert your json to php array(). After then you can iterate all data as your requirement.

Sign up to request clarification or add additional context in comments.

Comments

0

First I Need To Select My Primary Key

$sql="SELECT `survey_answers`,us_id FROM `user_survey_start`";

Then Put Value To ID

$id[] = $data['id'];

After That

$sql1="update user_survey_start set id2='$ids' where us_id=".$row[1];//run update sql
echo $sql1."<br>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.