十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
1、商品表建立商品基本信息主表CREATETABLEproduc。
創(chuàng)新互聯(lián)建站成立于2013年,先為隆堯等服務(wù)建站,隆堯等地企業(yè),進行企業(yè)商務(wù)咨詢服務(wù)。為隆堯企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
2、cidint10NOTNULLCOMMENT分類。
3、titlevarchar100NOTNULLCOMMENT商品名稱。
4、ddtimeint10NOTNULLCOMMENT添加時間,PRIMARYKEY。
商品分類展示
設(shè)置商品分類顯示不僅可使該購物系統(tǒng)的所有商品都分門別類的顯示出來,而且為用戶選擇商品提供了很大的方便。首先應(yīng)該建立一個單獨的type表用來存儲商品大類,之后在shangpin表中增加一個typeid字段,該字段中存儲的內(nèi)容是商品大類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
tddiv 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'本站暫無該類產(chǎn)品!/div";
}
else
{
?
table width="550" height="25" border="0" align="center" cellpadding="0" cellspacing="0"
tr
tddiv 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
tddiv 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");
?
其實一個表就可以做到了,實現(xiàn)一個無限級分類,如:
uid uname ucontent pid
商品id 名稱 描述 關(guān)聯(lián)pid
重點就在這個pid上,當(dāng)一個商品為父類時,pid為0,當(dāng)他為某一個商品的子類
時,pid即為父類的id,以此來無限極關(guān)聯(lián);
PS: 這樣,當(dāng)你每次點一個商品的同時,你要查詢表的數(shù)據(jù)。根據(jù)需求
顯示商品預(yù)覽效果;
至于你說的不顯示,代碼不貼出來大家怎么給你看!
不用太在意區(qū)分父類,與子類
因為父類與子類在同一個表中通過parent_id建立等級的!
點擊父類時傳遞父類本身的ID:product.asp?pid=4
點擊子類時也是傳遞子類本身的ID:product.asp?pid=12
在product.asp頁面里通過這個pid查詢商品(無論父類或子類)
sql = "select * from goods where pid ="request("pid")