我能够将这一行应用到phpMyAdmin上,它运行得很好。
SELECT id, date_format(`date`, '%m.%d.%Y') as `date` FROM TABLE ORDER BY date DESC LIMIT 1
问题在于,当我添加其余代码时,最近的日期在网页上显示为空白。我在这段代码中遗漏了什么吗?
<?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";
?>
感谢任何帮助。谢谢。
答案 0 :(得分:2)
。试试这个
$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";
答案 1 :(得分:0)
您没有设置$ date变量。您需要为$ result变量使用mysql_fetch_array函数。
例: `
$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); }
`