<table >
<tr>
<th>
生日提醒
</th>
</tr>
<tr>
<th>姓名</th>
<th>生日</th>
<th>时间</th>
</tr>
<?php
for($i=7;$i>=0;$i--)
{
$before_days = $i;//预设天数
$today = date("Y-m-d");
$t1 = strtotime($today);
$t2 = $t1 + $before_days*3600*24;
$birthday = date("m-d",$t2);//取得生日中的m-d
$sql = "SELECT * FROM `tongxunlu` WHERE `birthday` LIKE '%".$birthday."'";
$db_host = 'localhost';
$db_user = 'root';
$db_passw = '';
$db_name = 'kjms';
$conn = MySQL_connect($db_host,$db_user,$db_passw) or die ('数据库连接失败!');
mysql_query("set names ’utf8’ ");
MySQL_select_db($db_name,$conn) or die('数据库选定失败!'); //执行SQL语句(查询)
$result = MySQL_query($sql) or die('数据库操作失败!<br/>');
$num_rows=mysql_num_rows($result);
if($num_rows>0)
{
while ($row = mysql_fetch_assoc($result))
{
?>
<tr>
<td><?php echo $row['cn_name']?></td>
<td ><?php echo $row['birthday']?></td>
<?php
if($before_days!=0)
{
?>
<td><?php echo $before_days ?>天之后</td>
</tr>
<?php
}else{
?>
<td>今天</td>
</tr>
<?php
}
}
}
}
?>
</table>