PHP实现图书信息显示
来源:互联网 发布:刘道成mysql视频教程 编辑:程序博客网 时间:2024/05/21 10:57
一 数据库脚本
create database db_book;
use db_book;
create table db_book
(
id INT NOT NULL AUTO_INCREMENT,
bookname varchar(50)notnull,
author varchar(20),
price int,
bookpublic varchar(50),
pubtime date notnull,
PRIMARY KEY (id)
);
insert into db_book values(1,"明日之星","大神",20,"明日之星出版社","2016-12-12");
二 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"></head><body topmargin="0" leftmargin="0" bottommargin="0"><table width="703" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td bgcolor="#EF5E0F" ><table width="703" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td height="25" colspan="5" bgcolor="#FFFFFF"> </td> </tr> <tr> <td width="187" height="25" bgcolor="#F39A40"><div align="center">书名</div></td> <td width="173" bgcolor="#F39A40"><div align="center">作者</div></td> <td width="101" bgcolor="#F39A40"><div align="center">价格</div></td> <td width="131" bgcolor="#F39A40"><div align="center">出版社</div></td> <td width="105" bgcolor="#F39A40"><div align="center">出版时间</div></td> </tr> <?php $conn=mysql_connect("localhost","root","root"); mysql_select_db("db_book",$conn); mysql_query("set names gb2312"); $sql=mysql_query("select * from db_book order by id desc",$conn); $info=mysql_fetch_array($sql); if($info==false) { echo "暂无图书信息!";}else{ do { ?> <tr> <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $info[bookname];?></div></td> <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $info[author];?></div></td> <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $info[price];?></div></td> <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $info[bookpublic];?></div></td> <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $info[pubtime];?></div></td> </tr> <?php }while($info=mysql_fetch_array($sql)); } ?> </table></td> </tr></table></body></html>
三 运行结果