请 php 简单 产品分类代码

请 php 简单 产品分类代码,第1张

商品分类展示

设置商品分类显示不仅可使该购物系统的所有商品都分门别类的显示出来,而且为用户选择商品提供了很大的方便。首先应该建立一个单独的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: #666666font-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")

?>

你可以用断点查错法,在你的程序开始处,写一个echo 'x1'exit看看有没有显示,如果有,再一步步向下查,直到发现出错的地方.

连接数据库程序出错,最大可能是sql书写错误,所以,你可以先检查sql语句是否正确,可以把sql拷贝到mysql里运行下


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/7784625.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-09
下一篇 2023-04-09

发表评论

登录后才能评论

评论列表(0条)

保存