我有一个页面,我希望在表格的标题中显示昨天的日期。我尝试了这段代码,但无法显示日期值。 请帮助!
<?php
$con=mysqli_connect("localhost","root","") or die("Failed to connect with database!!!!");
mysqli_select_db($con,"db");
$result = mysqli_query($con,"SELECT * FROM `table`");
echo "<table border='1' align='center'>
<tr><th colspan='9'>DATA <?php echo date("d/M/Y",strtotime("-1 days")); ?></th></tr>
<tr>
<th>COLUMN A</th>
<th>COLUMN B</th>
</tr>";
echo "</table>";
mysqli_close($con);
?>
答案 0 :(得分:3)
你不需要在php字符串中使用echo
。
试试这个:
echo "<table border='1' align='center'>
<tr><th colspan='9'>DATA ".date("d/M/Y",strtotime("-1 days"))."</th></tr>
<tr>
<th>COLUMN A</th>
<th>COLUMN B</th>
</tr>";
答案 1 :(得分:1)
作为@Ranjith所说的替代方案,您也可以这样做:
<?php
$con=mysqli_connect("localhost","root","") or die("Failed to connect with database!!!!");
mysqli_select_db($con,"db");
$result = mysqli_query($con,"SELECT * FROM `table`");
?>
<table border='1' align='center'>
<tr>
<th colspan='9'>
DATA
<?=date("d/M/Y",strtotime("-1 days"));?>
</th>
</tr>
<tr>
<th>COLUMN A</th>
<th>COLUMN B</th>
</tr>";
</table>";
<?
mysqli_close($con);
在PHP代码中,您可以使用?>
和<?
在PHP和HTML之间切换。 <?=
是echo
的缩写形式。