【问题标题】:How to display only full name using php [duplicate]如何使用php仅显示全名[重复]
【发布时间】:2019-10-08 03:43:32
【问题描述】:

我设置了 MySQL 服务器,并尝试使用 Arduino 和以太网屏蔽从 SQL 服务器获取数据。问题是我无法从输出中删除无用的文本。

我对php不太了解,所以我不能尝试很多东西。

    <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>

我希望tryjson.php的输出是A1,但实际输出是[{"full_name":"A1"}]

【问题讨论】:

  • 你想要很多名字还是一个?
  • 你为什么使用json_encode而不是遍历数组?

标签: php html mysql sql arduino


【解决方案1】:

这是你想要的吗?

   <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>

【讨论】:

    猜你喜欢
    • 2013-10-01
    • 2012-12-21
    • 2011-01-27
    • 2014-04-13
    • 1970-01-01
    • 2011-11-29
    • 1970-01-01
    • 2018-02-02
    • 2018-03-31
    相关资源
    最近更新 更多