0

在不使用模板引擎的情况下,我一直在给自己上一门 PHP 基础进修课程(虽然我最近学习了一些 Smarty 和 Twig,但我觉得我应该继续练习基础 PHP),这是我的基本页面,显示车辆列表以及何时他们已注册:

 <?php 
 // Connects to your Database 
 mysql_connect("localhost", "testing", "testingpass") or die(mysql_error()); 
 mysql_select_db("cars1") or die(mysql_error()); 
 $data = mysql_query("SELECT * FROM autos") 
 or die(mysql_error()); 
 echo "<table border cellpadding=3>"; 
 while($info = mysql_fetch_array( $data )) 
 { 
 "<tr>"; 
 //echo "<td>"date("d M Y",strtotime($info['registered']));"</td> "; 
 echo "<td><tr>".$info['make'] ." ".$info['model'] ."</td><tr> "; 
 } 
 echo "</table>"; 
 ?> 

如果日期时间被注释掉,它会起作用,但如果没有注释,页面会显示为空白 - 我使用 MAMP 作为我的网络服务器,最新的 PHP。

对于一个简单的页面,这很好用,但我应该如何格式化这个日期?(我使用http://erikastokes.com/mysql-help/display-mysql-dates-in-other-formats.php上的教程来尝试这个)。

我应该做些什么改变来解决这个日期和时间的问题,否则它可以很好地作为一个基本的 MySQL php 查询。

4

2 回答 2

2

it should be like this

echo "<td>".date("d M Y",strtotime($info['registered']))."</td> ";

You have to use . for concantinate string.

于 2013-03-18T17:30:31.310 回答
0

First off, the reason your screen is blank, is because most default PHP installs have error reporting turned off. You'll need to edit your php.ini file to fix that. Open and search for display_errors and change it.

Second, the first error you're missing is you just have "<tr>" with no echo before it.

The second error you're most likely not seeing is that you're missing a concatenating operator .

echo "<td>"date("d M Y",strtotime($info['registered']));"</td> "

should be

echo "<td>" . date("d M Y",strtotime($info['registered'])) . "</td> "
于 2013-03-18T17:30:45.367 回答