product_list.php
来自「php模块设计。。。里面的模块很有学习价值」· PHP 代码 · 共 123 行
PHP
123 行
<?
// 取出某一类别之所有产品 BEGIN
$SQLStr = "SELECT * FROM product WHERE c_id='$c_id'";
$res = db_query($SQLStr);
$row = db_fetch_array($res);
// 取出某一类别之所有产品 END
// 取出某一类别之所有产品并按销售量排序 BEGIN
$SQLStr = "SELECT * FROM product WHERE c_id='$c_id' ORDER BY p_sell DESC";
$res_sell = db_query($SQLStr);
$row_sell = db_fetch_array($res_sell);
// 取出某一类别之所有产品并按销售量排序 END
?>
<table width="100%" border="1" align="center">
<tr>
<td align="center" colspan="2">最佳销售产品</td>
</tr>
<tr>
<td colspan="2">
<!-- 呈现最畅销的产品 BEGIN //-->
<table width="100%" border="1">
<tr>
<td rowspan="2" align="center">
<a href="product_show.php?p_id=<?=$row_sell['p_id']?>">
<img src="<?=$row_sell['p_pic']?>" width=140 height=193>
</a></td>
<td><a href="product_show.php?p_id=<?=$row_sell['p_id']?>">
<?=$row_sell['p_name']?></a></td>
</tr>
<tr>
<td><?=substr($row_sell[p_info],0,130)?>...
<a href="product_show.php?p_id=<?=$row_sell[p_id]?>">
[详情]</a></td>
</tr>
<tr>
<td colspan="2" align="center">
<a href="product_show.php?p_id=<?=$row_sell['p_id']?>">
特价:¥<?=$row_sell['p_price']?></a></td>
</tr>
</table>
<!-- 呈现最畅销的产品 END //-->
</td>
</tr>
<tr>
<td colspan="2" height="9"></td>
</tr>
<?
// 呈现类别中所有产品 BEGIN
for ($i=0;$i<$stop_num;$i++)
{
$row = db_fetch_array($res);
// 若类别中无数据 则中断循环
if(!$row)
break;
// 判断行数是否为偶数
if ($i%2==0)
echo "<tr>";
echo "<td width='295'><table width='100%' border='1'>";
echo "<tr><td width='72'><a href='product_show.php?p_id=" . $row['p_id'] . "'>";
echo "<img src='". $row['p_pic'] . "' width=70 height=86></a></td>";
echo "<td width='170'><a href='product_show.php?p_id=" . $row['p_id'] . "'>";
echo $row['p_name'] . "</a></td>";
echo "<td width='53'>¥" . $row['p_price'] . "</td></tr></table>";
if ($i%2==0)
echo "</tr>";
}
// 呈现类别中所有产品 END
?>
</table>
<?
// 决定启始笔数及结束笔数 BEGIN
if($res)
{
if(!isset($stop_num))
$stop_num = 10;
if(!isset($start_num))
$start_num = 0;
if(db_num_rows($res) > 0)
{
$pages = ceil(db_num_rows($res) / $stop_num) - 1;
$start_num = ($_GET['start_num'] > $pages)? 0:$_GET['start_num'];
if(db_num_rows($res) >= ($start_num * $stop_num))
@db_data_seek($res, $start_num * $stop_num);
else
@db_data_seek($res, 0);
}
}
// 决定启始笔数及结束笔数 END
?>
<!-- 呈现页次的下拉列表 BEGIN -->
到第<select name="sel1" onChange="location.href='<?=$PHP_SELF?>
?c_id=<?=$row_sell[c_id]?>&start_num='+(this.value-1)
+'&stop_num=<?=$stop_num?>'">
<?
for($i=0;$i<$pages+1;$i++)
echo "<option value='" . ($i+1) . "'" . (($start_num == $i)?' selected':'') . ">" . ($i+1) . "</option>\n";
?>
</select>页,
<!-- 呈现页次的下拉列表 END -->
<!-- 呈现笔数的下拉列表 BEGIN -->
每页显示<select name="sel2" onChange="location.href='<?=$PHP_SELF?>?c_id=<?=$row_sell[c_id]?>&start_num=<?=$start_num?>&stop_num='+this.value+''">
<?
for($i = 0;$i < 5;$i++)
{
$tmp_stop = ($i+1)*10;
echo "<option value='" . $tmp_stop . "'" . (($stop_num == $tmp_stop)?' selected':'') . ">" . $tmp_stop . "</option>\n";
}
?>
</select>笔, 共<?=db_num_rows($res)?>笔产品信息
<!-- 呈现笔数的下拉列表 END -->
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?