【问题标题】:PHP how to echo a row from the database based on the timestamp [duplicate]PHP如何根据时间戳从数据库中回显一行[重复]
【发布时间】:2018-07-28 09:48:57
【问题描述】:

在我的网站中,我所做的只是显示从数据库提交表单的用户的全名,当管理员单击名称时,它只会向单击的用户发送电子邮件。我的问题是,我怎样才能将名称列表排列到顶部为我提供最新名称和底部较旧名称的位置?我在那里有一个时间戳单元格,用于记录用户提交表单时的时间戳。这是我的代码

<?php


require_once('db_login.php');

    $stmt = $handler->prepare("SELECT * FROM formdata");

    $stmt->execute();
    while($result = $stmt->fetch()){

       $userid = $result['user_id'];
        echo "<a href='speaker_apps.php?infoid={$userid}'>". $result['fullname']."</a></br>";
    }

if(isset($_GET['infoid'])){


    $stmt = $handler->prepare("SELECT * FROM formdata where user_id='".$_GET['infoid']."'");
    $stmt->execute();
    $row = $stmt->fetch();
    echo "<p>id =".$row['email']."</p></br>";
}


?>

【问题讨论】:

  • 请注意,您的 prepare() 是一架永远不会飞的稻草飞机。您必须使用真实的prepared statement

标签: php pdo


【解决方案1】:

ORDER你的结果:

$stmt = $handler->prepare("SELECT * FROM formdata ORDER BY your_time_field DESC");

【讨论】:

    猜你喜欢
    • 2020-12-22
    • 1970-01-01
    • 2019-09-09
    • 2022-10-14
    • 2012-11-03
    • 1970-01-01
    • 2011-01-11
    • 2011-02-27
    • 1970-01-01
    相关资源
    最近更新 更多