-2

I set up MySQL server and i'm trying to get data from SQL server using Arduino and Ethernet shield.Problem is i can't remove unusefull text from output.

I don't know much about php so i can't try much things.

    <html>
    <head>
    <title>Try Session JSON</title>
    </head>
    <body>
    <?php

        $dbusername = "root";  
        $dbpassword = ""; 
        $server = "localhost"; 
        $dbconnect = mysqli_connect($server, $dbusername, $dbpassword);
        $dbselect = mysqli_select_db($dbconnect, "test");
        $sql="SELECT full_name FROM test.eattandance WHERE id=1";
        $records=mysqli_query($dbconnect,$sql);
        $json_array=array();
        while($row=mysqli_fetch_assoc($records))
    {
        $json_array[]=$row;
    }
        /*echo '<pre>';
        print_r($json_array);
        echo '</pre>';*/
    echo json_encode($json_array);
    ?>
    </body>
    </html>

I expect the output of tryjson.php to be A1,but the actual output is [{"full_name":"A1"}].

2
  • Do you want a lot of names or just one? Commented May 21, 2019 at 17:26
  • Why are you using json_encode instead of iterating over the array? Commented May 21, 2019 at 17:26

1 Answer 1

0

Is this what you wanted?

   <html>
    <head>
    <title>Try Session JSON</title>
    </head>
    <body>
    <?php

        $dbusername = "root";  
        $dbpassword = ""; 
        $server = "localhost"; 
        $dbconnect = mysqli_connect($server, $dbusername, $dbpassword);
        $dbselect = mysqli_select_db($dbconnect, "test");
        $sql="SELECT full_name FROM test.eattandance WHERE id=1";
        $records=mysqli_query($dbconnect,$sql);
        $json_array=array();
        while($row=mysqli_fetch_assoc($records))
        {
            $json_array[]=$row;
            echo $row['full_name'];
        }
    ?>
    </body>
    </html>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.