[英]php: how to fetch newest datetime from sql database using prepared statement?
In the following code i am trying to fetch only the newest datetime from a sql table full of email adresses (which are all the same) and datetimes, using a prepared statement: 在下面的代码中,我试图使用准备好的语句从充满电子邮件地址(都相同)和日期时间的sql表中仅获取最新的日期时间:
$sql = "SELECT * FROM usertokens WHERE user_mail = ?;";
//Create a prepared statement
$stmt = mysqli_stmt_init($conn);
//prepare prepared statement
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "SQL failed";
} else {
//Bind parameters to the placeholder
mysqli_stmt_bind_param($stmt, "s", $email);
//run params
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$resultCheck = mysqli_num_rows($result);
if ($row = mysqli_fetch_assoc($result)) {
$dt = date_create_from_format('Y-m-d H:i:s', $row['user_date']);
}}
At the moment it fetches only the first entry. 目前,它仅获取第一个条目。 How can i select the newest date time(and i do not want to select the lowest entry)?
我如何选择最新的日期时间(我不想选择最低的日期)? The table would look like this:
该表将如下所示:
:---user_mail---------user_date--------- :--- user_mail --------- user_date ---------
:----------------------------------------------- :-----------------------------------------------
:---some@mail.com----2018-06-06 20:28:16 :--- some@mail.com----2018-06-06 20:28:16
:---some@mail.com----2018-06-06 20:31:24 :--- some@mail.com----2018-06-06 20:31:24
:---some@mail.com----2018-06-06 20:33:44 :--- some@mail.com----2018-06-06 20:33:44
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.