dongtuoji5396 2013-03-18 17:27
浏览 94

MySQL查询中的Strtotime [基本PHP页面]

I've been giving myself a basic refresher course in PHP without using template engines (although I've learnt some Smarty and Twig recently I felt I should keep practising basic PHP), and this is my basic page displaying a list of vehicles and when they were registered:

 <?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>"; 
 ?> 

It works if the datetime is commented out, but if it's uncommented the page appears blank - I'm using MAMP as my webserver, latest PHP.

For a simple page this works well, but how should I format this date? (I used the tutorial at http://erikastokes.com/mysql-help/display-mysql-dates-in-other-formats.php to try this).

What changes should I make to fix this problem with the date and time, as otherwise it works well as a basic MySQL php query.

  • 写回答

2条回答 默认 最新

  • duandeng2011 2013-03-18 17:30
    关注

    it should be like this

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

    You have to use . for concantinate string.

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)