PHP中的循环语句输出企业公告信息

来源:互联网 发布:刘道成mysql视频教程 编辑:程序博客网 时间:2024/06/05 23:55

一 数据库脚本

CREATE TABLE `tb_person` (  `id` int(4) NOT NULL,  `p_title` varchar(50) NOT NULL,  `p_content` mediumtext NOT NULL,  `p_time` date NOT NULL,  `u_id` int(4) NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=gb2312;---- 转存表中的数据 `tb_person`--INSERT INTO `tb_person` (`id`, `p_title`, `p_content`, `p_time`, `u_id`) VALUES(11, '乒乓球单打决赛', '今天下午4点,在体育馆举行本次乒乓球球单打决赛。\r\n参赛人员:全体员工\r\n                                     2016年12月4日', '2016-12-04', 10),(12, '换休', '由于公司这周日停电,所以将周一与周日换休,周日正常上班,周一休息,请注意上班时间', '2016-12-04', 9);

 

二 PHP脚本
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>企业公告信息展示</title><link rel="stylesheet" type="text/css" href="css/font.css"><style type="text/css"><!--.STYLE1 {font-size: 24px;font-weight: bold;}--></style></head><body><table width="703" border="0" align="center" cellpadding="0" cellspacing="0">  <tr>    <td  bgcolor="#669933" ><table width="703" border="0" align="center" cellpadding="0" cellspacing="1">      <tr>        <td height="25" colspan="5" align="center" bgcolor="#FFFFFF"><span class="STYLE1">企业公告信息展示</span></td>      </tr>      <tr>        <td width="187" height="25" align="center" bgcolor="#CCFF66">标题</td>        <td width="173" align="center" bgcolor="#CCFF66">内容</td>        <td width="101" align="center" bgcolor="#CCFF66">发布时间</td>      </tr>  <?php  $conn=mysql_connect("localhost","root","root");  mysql_select_db("db_database04",$conn);  mysql_query("set names gb2312");  $sql=mysql_query("select * from tb_person order by u_id desc",$conn);  $info=mysql_fetch_array($sql);   if($info==false){  echo "暂无公告信息!";}else{     do{  ?>      <tr>        <td height="25" align="center" bgcolor="#FFFFFF"><?php echo $info[p_title];?></td>        <td height="25" align="center" bgcolor="#FFFFFF"><?php echo $info[p_content];?></td>        <td height="25" align="center" bgcolor="#FFFFFF"><?php echo $info[p_time];?></td>      </tr>  <?php      }while($info=mysql_fetch_array($sql));  }  ?>    </table></td>  </tr></table></body></html>
 
三 运行效果

 
原创粉丝点击