① html css製作家用商品分類頁面
<!doctypehtml>
<htmllang="en">
<head>
<metacharset="UTF-8">
<title>Document</title>
<style>
*{margin:0;padding:0;box-sizing:border-box;}
a{color:#666;text-decoration:none;}
.menu{width:220px;}
.menuh2{width:100%;height:36px;line-height:36px;font-size:18px;padding-left:10px;background:#0F7CBF;}
.menuh2a{color:#fff;}
.menu.itemh3{height:30px;line-height:30px;padding-left:15px;background:#E4F1FA;}
.menu.itemh3a{color:#0F7CBF;font-size:14px;}
.menu.itemp{padding:15px;line-height:18px;}
.menu.itempa{font-size:12px;}
</style>
</head>
<body>
<divclass="menu">
<h2><ahref="#">家用電器</a></h2>
<divclass="item">
<h3><ahref="#">大家電</a></h3>
<p>
<ahref="#">平板電視</a><ahref="#">洗衣機</a><ahref="#">冰箱</a>
<ahref="#">空調</a><ahref="#">煙機/灶具</a><ahref="#">熱水器</a>
<ahref="#">冷櫃/酒櫃</a><ahref="#">消毒櫃</a><ahref="#">家庭影院</a>
</p>
</div>
<divclass="item">
<h3><ahref="#">大家電</a></h3>
<p>
<ahref="#">平板電視</a><ahref="#">洗衣機</a><ahref="#">冰箱</a>
<ahref="#">空調</a><ahref="#">煙機/灶具</a><ahref="#">熱水器</a>
<ahref="#">冷櫃/酒櫃</a><ahref="#">消毒櫃</a><ahref="#">家庭影院</a>
</p>
</div>
<divclass="item">
<h3><ahref="#">大家電</a></h3>
<p>
<ahref="#">平板電視</a><ahref="#">洗衣機</a><ahref="#">冰箱</a>
<ahref="#">空調</a><ahref="#">煙機/灶具</a><ahref="#">熱水器</a>
<ahref="#">冷櫃/酒櫃</a><ahref="#">消毒櫃</a><ahref="#">家庭影院</a>
</p>
</div>
<divclass="item">
<h3><ahref="#">大家電</a></h3>
<p>
<ahref="#">平板電視</a><ahref="#">洗衣機</a><ahref="#">冰箱</a>
<ahref="#">空調</a><ahref="#">煙機/灶具</a><ahref="#">熱水器</a>
<ahref="#">冷櫃/酒櫃</a><ahref="#">消毒櫃</a><ahref="#">家庭影院</a>
</p>
</div>
</div>
</body>
</html>
兼容IE8+
② 請 php 簡單 產品分類代碼
商品分類展示
設置商品分類顯示不僅可使該購物系統的所有商品都分門別類的顯示出來,而且為用戶選擇商品提供了很大的方便。首先應該建立一個單獨的type表用來存儲商品大類,之後在shangpin表中增加一個typeid欄位,該欄位中存儲的內容是商品大類id值,利用這個值就可以確定該商品屬於那一類。商品分類展示是在showfenlei.php中完成的,代碼如下:
<!--*******************************showfenlei.php*******************************-->
<?php
include("top.php");
?>
<table width="800" height="438" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="200" height="438" valign="top" bgcolor="#E8E8E8"><div align="center">
<?php include("left.php");?>
</div></td>
<td width="10" background="images/line2.gif"></td>
<td width="590" valign="top"><table width="590" height="20" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="left">
<?php
$sql=mysql_query("select * from type order by id desc",$conn);
$info=mysql_fetch_object($sql);
if($info==false)
{
echo "本站暫無商品!";
}
else
{
do
{
echo "<a href='showfenlei.php?id=".$info->id."'>".$info->typename."</a>";
}
while($info=mysql_fetch_object($sql));
}
?>
</div></td>
</tr>
</table>
<?php
if($_GET[id]=="")
{
$sql=mysql_query("select * from type order by id desc limit 0,1",$conn);
$info=mysql_fetch_array($sql);
$id=$info[id];
}
else
{
$id=$_GET[id];
}
$sql1=mysql_query("select * from type where id=".$id."",$conn);
$info1=mysql_fetch_array($sql1);
$sql=mysql_query("select count(*) as total from shangpin where typeid='".$id."' order by addtime desc ",$conn);
$info=mysql_fetch_array($sql);
$total=$info[total];
if($total==0)
{
echo "<div align='center'>本站暫無該類產品!</div>";
}
else
{
?>
<table width="550" height="25" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="left"><span style="color: #666666; font-weight: bold"><span style="color: #000000">本類商品>></span><?php echo $info1[typename];?></span>
</div></td>
</tr>
</table>
<table width="550" height="10" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td background="images/line1.gif"></td>
</tr>
</table>
<table width="550" height="70" border="0" align="center" cellpadding="0" cellspacing="0">
<?php
$pagesize=10;
if ($total<=$pagesize)
{
$pagecount=1;
}
if(($total%$pagesize)!=0)
{
$pagecount=intval($total/$pagesize)+1;
}
else
{
$pagecount=$total/$pagesize;
}
if(($_GET[page])=="")
{
$page=1;
}
else
{
$page=intval($_GET[page]);
}
$sql1=mysql_query("select * from shangpin where typeid=".$id." order by addtime desc limit ".($page-1) *$pagesize.",$pagesize ",$conn);
while($info1=mysql_fetch_array($sql1)) //顯示商品信息
{
?>
……
<?php
}
?>
</table>
<table width="550" height="25" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="right"> 本站共有該類商品
<?php
echo $total;
?>
件每頁顯示<?php echo $pagesize;?>件第<?php echo $page; ?> 頁/共<?php echo $pagecount; ?>頁
<?php
if($page>=2) //商品分頁顯示
{
?>
<a href="showfenlei.php?id=<?php echo $id;?>&page=1" title="首頁"><font face="webdings"> 9 </font></a>
<a href="showfenlei.php?id=<?php echo $id;?>&page=<?php echo $page-1;?>" title="前一頁"><font face="webdings"> 7 </font></a>
<?php
}
if($pagecount<=4){
for($i=1;$i<=$pagecount;$i++){
?>
<a href="showfenlei.php?id=<?php echo $id;?>&page=<?php echo $i;?>"><?php echo $i;?></a>
<?php
}
}
else
{
for($i=1;$i<=4;$i++){
?>
<a href="showfenlei.php?id=<?php echo $id;?>&page=<?php echo $i;?>"><?php echo $i;?></a>
<?php
}
?>
<a href="showfenlei.php?id=<?php echo $id;?>&page=<?php echo $page-1;?>" title="後一頁"><font face="webdings"> 8 </font></a>
<a href="showfenlei.php?id=<?php echo $id;?>&page=<?php echo $pagecount;?>" title="尾頁"><font face="webdings"> : </font></a>
<?php
}
?>
</div></td>
</tr>
</table>
<?php
}
?>
</td>
</tr>
</table>
<?php
include("bottom.php");
?>