---
title: "PHP实现图书信息显示"
author: "cakin24"
date: "2016-12-27T21:33:38Z"
tags: []
categories: ["编程语言"]
slug: "php"
draft: false
lastmod: "2016-12-27T21:33:38Z"
id: 2347718
url: "https://cakin24.iteye.com/blog/2347718"
---

一 数据库脚本

01. `create database db_book;`
02. `use db_book;`
03. `create table db_book`
04. `(`
05. `id INT NOT NULL AUTO_INCREMENT,`
06. `bookname varchar(50)notnull,`
07. `author varchar(20),`
08. `price int,`
09. `bookpublic varchar(50),`
10. `pubtime date notnull,`
11. `PRIMARY KEY (id)`
12. `);`
13. `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">&nbsp;</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>
```

 

三 运行结果

![](http://dl2.iteye.com/upload/attachment/0122/2457/136f43ce-9514-3ba6-ba60-6a482906b294.png)