[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=utf-8" />
<title>商品显示页面</title>
<style type="text/css">
table,th,td{
border:#000 solid 1px;
}
table{
width:980px;
margin:auto;
font-size:14px;
}
caption{
font-size:24px;
font-weight:bold;
}
</style>
</head>
<script type="text/javascript">
//提示删除确认函数
function jump(id){
if(confirm('确定要删除吗?')){
//跳转至del.php并提交要删除的产品id
location.href='del.php?id='+id;
}
}
</script>
<body>
<?php
//连接数据库
require "../public/dbcn.php";
$dbcn->exec('set names utf8');
$rs=$dbcn->query('select * from products');
?>
<a href="add.php">添加商品</a>
<table width="980" border="1">
<tr>
<th>编号</th>
<th>商品名称</th>
<th>商品规格</th>
<th>价格</th>
<th>库存量</th>
<th>图片</th>
<th>网站</th>
<th>修改</th>
<th>删除</th>
</tr>
<?php
//循环匹配成关联数组
while($rows=$rs->fetch(PDO::FETCH_ASSOC)){//返回结果读取为关联数组
echo'<tr>';
echo'<td>'.$rows['proID'].'</td>';
echo'<td>'.$rows['proname'].'</td>';
echo'<td>'.$rows['proguide'].'</td>';
echo'<td>'.$rows['proprice'].'</td>';
echo'<td>'.$rows['proamount'].'</td>';
echo'<td>'.$rows['proimages'].'</td>';
echo'<td>'.$rows['proweb'].'</td>';
echo'<td><input type="button" value="修改" onclick="location.href
=\'modify.php ? id='.$rows['proID'].'\'"/></td>';
echo'<td><input type="button" value="删除" onclick="jump
('.$rows['proID'].')" /></td>';
echo'</tr>';
}
?>
</table>
</body>
</html>