【php开源代码栏目提醒】:网学会员鉴于大家对php开源代码十分关注,论文会员在此为大家搜集整理了“GOODLIST.PHP”一文,供大家参考学习
<?php
//使用session记录查询语句
session_start();
session_register("query_bak");
?>
<html>
<head>
<base target="_self">
<link rel="stylesheet" herf="chaoshi.css">
<script language="JavaScript">
<!--
function openwindow(theURL, winName, features, form)
{
var str;
str = theURL + form.goods_num.value;
window.open(str, winName, features);
}
//-->
</script>
</head>
<?php
//链接到MySQL服务器
$db_host = "localhost";
$db_user = "root";
$db_pass = "770408";
$db_name = "shopping";
$link = @mysql_pconnect($db_host, $db_user, $db_pass);
if (!$link)
{
mysql_die();
}
//选择数据库
mysql_select_db($db_name);
//判断当前情况
//第一次调用,关键字查询
if (IsSet($search) && IsSet($key_words))
{
$query_bak = "select * from goods where name like '%$key_
words%' or attrib like '%$key_words%'";
$query = $query_bak;
}
//第一次调用,id查询
else if (IsSet($id) && strlen($id))
{
$query_bak = "select * from goods where id like '%$id%'";
$query = $query_bak;
}
//页面自定向
else if (IsSet($query_bak))
{
$query = $query_bak;
}
//非以上情况,则出现了非法操作
else
{
echo "<H3>页面无效</H3><br>";
exit();
}
//得到
查询结果
$result = my
sql_query($query, $link);
//如果结果为0,退出
$num =
mysql_num_rows($result);
if ($num == 0)
{
echo "<H3>很抱歉,没有这种商品。</H3><br>";
exit();
}
//计算页面总页数,每页显示的记录数目为5
$records_per_page = 5;
$total_page_nums = ceil($num/5);
//将查询的记录主键值记录在某个数组中
$record = array();
while ($row=mysql_fetch_array($result))
{
$record[] = $row['key_goods'];
}
//如果是第一次显示,设置当前页码
if (!IsSet($cur_page))
{
$cur_page = 1;
}
//设置上一页的页码
$last_page = $cur_page - 1;
if ($last_page < 1)
{
$last_page = 1;
}
//设置下一页的页码
$next_page = $cur_page + 1;
if ($next_page > $total_page_nums)
{
$next_page = $total_page_nums;
}
?>
<body>
<div align="left">
<table border="0" width="500" height="22">
<tr>
<td width="500" height="2" valign="top">
<font class="myfont1">
共有<? echo $num; ?>条记录满足要求。
<? echo $cur_page; ?>/
<? echo $total_page_nums; ?> 页 </font>
<?php
echo '<td align="left" width="120" height="2"></td>';
echo '<td align="middle" width="120" height="2">';
if ($last_page != $cur_page)
{
//显示上一页的链接
echo "<a href=\"goodlist.php?cur_page=".$last_page."\">";
echo "上一页</a> ";
}
if ($next_page != $cur_page)
{
//显示下一页的链接
echo "<a href=\"goodlist.php?cur_page=".$next_page."\">";
echo "下一页</a> ";
}
//显示首页链接
echo '<td align="middle" width="40" height="1">';
echo '<a href="firstpage.htm">首页';
echo '</a>';
?>
</td>
</tr>
</table>
</div>
<div align="left">
<table border="0" width="518" height="107" align="left">
<tr>
<td width="32" height="8" valign="top"></td>
<td width="476" height="8" valign="top" colspan="3">
<hr color="#008080">
</td>
</tr>
<?php
//根据页码计算起始记录编号
$start_record = ($cur_page-1)*5;
//根据页码计算下一个起始记录编号
$end_record = $cur_page*5;
if ($end_record > $num)
{
$end_record = $num;
}
//根据编号范围,通过$record数组记录的主键值显示记录
for ($cur_record=$start_record; $cur_record<$end_record; $cur_record++)
{
$key_goods = $record[$cur_record];
//根据主键值查询记录
$query = "select * from goods where key_goods = $key_goods";
$result1 = mysql_query($query, $link);
$row1 = mysql_fetch_array($result1);
//用于显示字符串
$display_price = sprintf("%.2f", $row1['price']/100);
$display_num = $cur_record + 1;
?>
<tr>
<td width="43" height="1" valign="middle" rowspan="2" align="center">
<h3><? print $display_num; ?></h3>
</td>
<td width="344" height="25" valign="middle">
<p align="center">
<font class="myfont1">
<? print $row1['name']; ?>
</font>
</td>
<td width="121" height="29" valign="middle" colspan="2">
<font class="myfont1">
<? print $display_price; ?>
</font>
</td>
</tr>
<tr>
<td width="344" height="1" valign="middle">
<p align="center">
<font class="myfont1">
<? print $row1['attrib']; ?>
</font>
</td>
<form method="post" action="">
<td width="69" height="1" valign="top">
<font class="myfont1">数量
<input type="text" name="goods_num" size="2" value="1">
</font>
</td>
<td width="48" height="1" valign="middle">
<?php
$href_string = "buy.php?k