【问题标题】:How to use mysqli_fetch_array to get just one result from a select query?如何使用 mysqli_fetch_array 从选择查询中获取一个结果?
【发布时间】:2018-07-16 07:41:33
【问题描述】:
$sqlresult = mysqli_query($dbconnection, "SELECT datetime, pagecontent, 
editedby FROM content ORDER BY datetime DESC LIMIT 1");

我正在上一门 Web 开发课程,它说我可以通过使用 mysqli_fetch_array 从我的选择查询中获得一个结果,但我不确定如何。我试过谷歌搜索,但找不到任何我能理解的答案。

在数据库中,我有内容、日期时间和编辑者。

【问题讨论】:

标签: php sql select mysqli


【解决方案1】:

我认为这将是一种更简单的输出结果的方式。

$query = "SELECT datetime, pagecontent,editedby FROM content ORDER BY datetime DESC LIMIT 1";

$result = mysqli_query($connection, $query);


    while($row = mysqli_fetch_array($result))
    {
        $datetime = $row['datetime'];
        $pagecontent = $row['pagecontent'];
        $editedby = $row['editedby'];

        echo $datetime . " " . $pagecontent  ." " . $editedby;
    }

【讨论】:

    猜你喜欢
    • 2016-11-14
    • 2020-02-04
    • 1970-01-01
    • 2023-03-23
    • 2016-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-14
    相关资源
    最近更新 更多