请php 简单 产品分类代码
发布网友
发布时间:2022-05-01 13:50
我来回答
共2个回答
热心网友
时间:2022-04-22 10:54
商品分类展示
设置商品分类显示不仅可使该购物系统的所有商品都分门别类的显示出来,而且为用户选择商品提供了很大的方便。首先应该建立一个单独的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");
?>
热心网友
时间:2022-04-22 12:12
页面shopping.php代码:
<?
session_start();
//$CatalogSN = $_POST['CatalogSN'];
?>
<html>
<head>
<title> 选购商品 </title>
</head>
<body>
<p align = "center"> <font size = "5" color = "#0000FF"> 选购商品 </font> </p>
<p> 请在看中的商品项目的数量栏中输入所需数量: </p>
<form Action = "putinbag.php" Method = "POST">
<input type = "hidden" name = "tellme" value = <? echo $CatalogSN; ?>>
<table Border = "2">
<tr BGCOLOR = "#BOBOFF">
<td> 商品编号 </td>
<td> 商品名称</td>
<td> 单价 </td>
<td> 数量 </td>
<td> 商品简介 </td>
</tr>
<?php
$conn_ID = mysql_connect('localhost','root','root');
mysql_query("SET NAMES 'gbk'");
mysql_select_db("users",$conn_ID);
/*$row = "select*from 'procts'";
$result = mysql_query($row);
$anyrow = mysql_fetch_array($result)
while($anyrow)
{
echo ".$anyrow["ItemSN"].";
".$anyrow["ItemName"].";
".$anyrow["Prcice"].";
".$anyrow["Detail"].";
}*/
$CatalogSN = $_GET['CatalogSN']; //
$Thiskind = "Select*From procts Where CatalogSN = '$CatalogSN'";
$Thiskind = $Thiskind. "Order By ItemSN";
//$Item1 = $_POST['ItemSN'];
//$Item2 = $_POST['ItemName'];
//$Item3 = $_POST['Price'];
//$Item4 = $_POST['Detail'];
//$rec_ID = mysql_query($Thiskind);
$i = 1;
while($EveryRow = mysql_fetch_array($rec_ID = mysql_query($Thiskind)))
{
$Item1 = $EveryRow["ItemSN"];
$Item2 = $EveryRow["ItemName"];
$Item3 = $EveryRow["Price"];
$Item4 = $EveryRow["Detail"];
$Makennames[$i] = "Qty".$i;
echo "<tr> <td> ".$Item1."</td>";
"<td> ".$Item2."</td>";
"<td> ".$Item3."</td>";
"<td> <input type = text name = $Makennames[$i] size = 6> </td>";
"<td> ".$Item4."</td> </tr>";
$i++;
}
$total = $i;
?>
</Table>
<input type = hidden name = howmany value = <? echo $total; ?>>
<p> <input Type = "submit" Value = "好,我买了!" >
<input type = "reset" value = "还没想好" name = "B1">
<a href = "checkbag.php"> 查看己购物品 </a> </p>
</form>
<hr align = "center">
<p align = center>
<?
$rec_ID = mysql_query("select*from Catalog ");
while($Anyrow = mysql_fetch_array($rec_ID))
{
$Item1 = $Anyrow["CatalogSN"];
$Item2 = $Anyrow["CataInfo"];
echo "<p align = center> <a href = 'shopping.php? CatalogSN = $Item1'>
$Item2 </a> <br> <p>";
}
mysql_close($conn_ID);
?>
</p>
</body>
</html> //页面商品编号 商品名称 单价 数量 商品简介
1、$CatalogSN = $_GET['CatalogSN'];
定义的post,变成get...
2、
$Thiskind = "Select*From procts Where CatalogSN = '$CatalogSN'";
select * from ,中间得留点空吧?还有 表名称和字段名最好用一下反向引号(ESC键下面)。:
$Thiskind = "Select * From `procts` Where `CatalogSN` = '$CatalogSN'";
3、$Thiskind = $Thiskind. "Order By ItemSN";
比如:$Thiskind = $Thiskind. ' Order By ItemSN';追问我问的是输出分类,不是购物车 -_- b