[英]MySQL/PHP - Display Recent Date
I was able to apply this line onto phpMyAdmin and it worked just fine. 我能够将这一行应用到phpMyAdmin上,并且工作正常。
SELECT id, date_format(`date`, '%m.%d.%Y') as `date` FROM TABLE ORDER BY date DESC LIMIT 1
The problem is that when I added the rest of the code, the recent date shows up blank on the webpage. 问题是,当我添加其余代码时,最近日期在网页上显示为空白。 Am I missing something in this code?
我在这段代码中缺少什么吗?
<?php
$query = "SELECT id, date_format(`date`, '%m.%d.%Y') as `date` FROM TABLE ORDER BY date DESC LIMIT 1";
$result = mysql_query($query);
echo "$date";
?>
Any help is appreciated. 任何帮助表示赞赏。 Thank you.
谢谢。
. 。 Try this
尝试这个
$query = "SELECT id, date_format(`date`, '%m.%d.%Y') as `date` FROM TABLE ORDER BY. date DESC LIMIT 1";
$result = mysql_query($query);
$r = mysql_fetch_assoc($result);
$date = $r['date'];
echo "$date";
You didn't set $date variable. 您没有设置$ date变量。 You need to use mysql_fetch_array function for your $result variable.
您需要为$ result变量使用mysql_fetch_array函数。
Ex: ` 例如:
$query = "SELECT id, date_format('date', '%m.%d.%Y') as 'date' FROM TABLE ORDER BY date DESC LIMIT 1";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
print_r($row); }
` `
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.