请大家帮帮忙,我想让php echo 显示在页面的时间,只显示其中一部份。
例如:只显示 月、日、小时、分钟 "03-10 16:23"
下面"['times']"是我数据存入数据库的时间字段名称。
代码:<?php $sql = mysql_query("SELECT * FROM `tb_routes` ORDER BY `tb_routes`.`times` DESC LIMIT 5");
while($row=mysql_fetch_array($sql)){
echo ".$row['route'].";
echo ".$row['times'].";
}
?>谢谢
例如:只显示 月、日、小时、分钟 "03-10 16:23"
下面"['times']"是我数据存入数据库的时间字段名称。
代码:<?php $sql = mysql_query("SELECT * FROM `tb_routes` ORDER BY `tb_routes`.`times` DESC LIMIT 5");
while($row=mysql_fetch_array($sql)){
echo ".$row['route'].";
echo ".$row['times'].";
}
?>谢谢
没有显示出来,
我上面的代码有个循环 while,每次循环,输出数据存入的不同时间,例:下面是我想要的效果a t u 03-10 23:12
c f t 03-09 12:24
h d r 02-23 09:15谢谢
echo date("m-d H:i",strtotime($dt));
while($row=mysql_fetch_array($sql)){
echo ".$row['unit'].";
echo ".$row['route'].";
echo ".$row['times'].";
}
?>
我上面的代码有个循环 while,每次循环,输出数据,存入数据的不同时间,
数据存入数据库的时间格式是 2010-03-10 16:15:25
每条数据存入数据库都是不同的时间,例:下面是我想要的效果a t u 03-10 23:12
c f t 03-09 12:24
h d r 02-23 09:15谢谢
echo date("m-d H:i",strtotime($row['unit']));
echo date("m-d H:i",strtotime($row['route']));
echo date("m-d H:i",strtotime($row['times']));
}
while($row=mysql_fetch_array($sql)){
echo $row['route'];
echo $row['time1'];
}
?>
while($row=mysql_fetch_array($sql)){
echo ".$row['times'].";
}
?>以上正常输出结果如下:
a t u 2011-03-10 23:12:15
c f t 2011-03-09 12:24:23
h d r 2011-02-23 09:15:34能不能再echo输出时使用一个函数控制输出,echo ".$row['times'].";
例如:只显示 月、日、小时、分钟----- 格式("03-10 16:23")a t u 03-10 23:12
c f t 03-09 12:24
h d r 02-23 09:15
原句:SELECT * FROM `tb_routes` ORDER BY `tb_routes`.`times` DESC LIMIT 5改后:SELECT DATE_FORMAT(times,'%m-%d %k:%i') FROM `tb_routes` ORDER BY `tb_routes`.`times` DESC LIMIT 5select查询列,后面括号里的内容好像不对,执行错误DATE_FORMAT(times,'%m-%d %k:%i')大家在帮帮忙,改改,谢谢
<?php $sql = mysql_query("SELECT * FROM `tb_routes` ORDER BY `tb_routes`.`times` DESC LIMIT 5");
while($row=mysql_fetch_array($sql)){
echo $row['unit'];
echo ' ';
echo $row['route'];
echo ' ' ;
echo date("m-d H:i",strtotime($row['times']));
echo '<br>' ;
}
?>
foreach($te as $row){
$s = substr($row,0,6);
$time = substr($row,12,12);
echo $s.$time.'<br>';
}
以下是我的代码:有四个页面
1>php文件 2>数据库文件 3>表单页面提交数据 4>主页面数据由表单提交存入数据库,数据保存时间为、当时的系统时间,数据库的数据,保存时间的字段为“createtime”3表单页面提交数据到2>数据库文件保存数据完成后,4在主页面刷新或重新载入调用1>php文件后即可看到新数据数据库保存的数据时间字段“createtime” 格式 2010-03-11 16:25:12
我想要的就是,在主页面显示的数据时间格式 03-11 16:25
<?php
$connection=mysql_connect("localhost","root","123");
mysql_select_db("db_routes",$connection) ;
$sql = mysql_query("SELECT * FROM `tb_routes` ORDER BY `tb_routes`.`createtime` DESC LIMIT 5");
echo "<div>";
echo "<ul>";
while($row=mysql_fetch_array($sql)){
echo "<li><a href='si.php?id=".$row['unit']."'></li>";
echo $row['unit']."</a>";
echo "<li><a href='gn.php?id=".$row['route']."'></li>";
echo $row['route']."</a>";
echo "<li>".$row['quotation']."</li>";
echo "<li>".$row['createtime']."</li>";
}
echo "</ul>";
echo "</div>";
mysql_free_result($sql);
mysql_close($connection);
?>
echo "<li>".date("m-d H:i",strtotime($row['createtime']))."</li>";大家说这么多,其实就是告诉,date可以将任意一个时间戳格式的数据,转换成一个你指定格式要求的(日期)字符串而strtotime这个就是将任意一个(日期)字符串转换成时间戳格式的数据,你怎么就不知道变通呢date("m-d H:i",strtotime(xxxx)) 相当于这个就是一个固定用法了,你直接把你的内容替换成xxxx就可以了,还非要给你具体写出来吗?