以下代码是我正在处理的电子商务网站。分页为查询的第一页选择正确的内容,但在第二页上选择了错误的内容。我究竟做错了什么?任何帮助将不胜感激
<?php ob_start();
include "config.php";
function currency($from_Currency,$to_Currency,$amount) {
$amount = urlencode($amount);
$from_Currency = urlencode($from_Currency);
$to_Currency = urlencode($to_Currency);
$url = "http://www.google.com/ig/calculator?hl=en&q=$amount$from_Currency=?$to_Currency";
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$rawdata = curl_exec($ch);
curl_close($ch);
$data = explode('"', $rawdata);
$data = explode('.', $data['3']);
$data[0] = str_replace(" ", "",preg_replace('/\D/', '', $data[0]));
if(isset($data[1])){
$data[1] = str_replace(" ", "",preg_replace('/\D/', '', $data[1]));
$var = $data[0].".".$data[1];
} else{
$var = $data[0];
}
return round($var,2); }
?>
<?php require_once("../include/membersite_config.php"); ?>
<?php
// Create connection
$con=mysqli_connect("RichWebmasterReg.db.10749243.hostedresource.com","RichWebmasterReg","Apple@1993","RichWebmasterReg");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Products</title>
<link href="../jscss/pproducts.css" rel="stylesheet" type="text/css">
<link href="../jscss/main.css" rel="stylesheet" type="text/css">
<link href="../jscss/heads.css" rel="stylesheet" type="text/css">
<link href='http://fonts.googleapis.com/css?family=Oswald:400,700,300' rel='stylesheet' type='text/css'>
</head>
<body>
<?php
require('../nmheader.php');
?>
<br><br><br><br>
<?php
///////////////////Pagination/////////////////////////////////////
$perpage = 8; //
$pages_query = mysql_query("SELECT count(p_name) from product ");//
$pages = ceil(mysql_result($pages_query, 0)/ $perpage ); //
$page = (isset($_GET['page']))? (int)$_GET['page']:1; //
$start = ($page - 1) * $perpage; //
/////////////////// EndPagination//////////////////////////////////
//$query="SELECT * FROM product ORDER by date_added DESC LIMIT $start, $perpage";
session_start();
$category1 = $_REQUEST['categorys'];
switch($category1)
{
case $category1 == 'ALL':
$category = 'ALL';
$query="SELECT * FROM product ORDER by date_added DESC LIMIT $start, $perpage";
$sel = 1;
break;
case $category1 == 'BOTTLES':
$category = 'BOTTLES';
$sel = 2;
$query="SELECT * FROM product WHERE cat = 'bottles' ORDER by date_added DESC LIMIT $start, $perpage";
break;
case $category1 == 'EXERCISE APPAREL':
$category = 'EXERCISE APPAREL';
$query="SELECT * FROM product WHERE cat = 'exercise apparel' ORDER by date_added DESC LIMIT $start, $perpage";
$sel = 4;
break;
case $category1 == 'TOP SELLERS':
$category = 'TOP SELLERS';
$query="SELECT * FROM product WHERE cat = 'Top sellers' ORDER by date_added DESC LIMIT $start, $perpage";
$sel = 6;
break;
case $category1 == 'MUSCLE FORMULAS':
$category = 'MUSCLE FORMULAS';
$query="SELECT * FROM product WHERE cat = 'muscle formulas'ORDER by date_added DESC LIMIT $start, $perpage";
$sel = 5;
break;
case $category1 == 'SPECIALS':
$category = 'SPECIALS';
$query="SELECT * FROM product WHERE cat = 'specials' ORDER by date_added DESC LIMIT $start, $perpage";
$sel = 7;
break;
case $category1 == 'SUPPLIMENTS':
$category = 'SUPPLIMENTS';
$query="SELECT * FROM product WHERE cat = 'suppliments' ORDER by date_added DESC LIMIT $start, $perpage";
$sel = 3;
break;
default:
$query="SELECT * FROM product ORDER by date_added DESC LIMIT $start, $perpage";
}
$result = mysql_query($query);
$total = mysql_num_rows($result);
$showing = $perpage > $total? $total: $perpage;
?>
<div style="font-family:Oswald; font-size:120%"><?php echo $category;?> </div>
<form action="products.php" method="post" >
<select name="categorys" style="padding:0px !important; font-size:12px !important; ">
<option value="ALL" <?php if($sel == 1)echo 'selected';?> >All</option>
<option value="BOTTLES" <?php if($sel == 2)echo 'selected';?>> Bottles</option>
<option value="SUPPLIMENTS" <?php if($sel == 3)echo 'selected';?>>Supplements</option>
<option value="EXERCISE APPAREL" <?php if($sel == 4)echo 'selected';?>> Exercise Apparel</option>
<option value="MUSCLE FORMULAS" <?php if($sel == 5)echo 'selected';?>>Muscle Formulas</option>
<option value="TOP SELLERS" <?php if($sel == 6)echo 'selected';?>>Top Sellers</option>
<option value="SPECIALS" <?php if($sel == 7)echo 'selected';?>>Specials</option>
</select>
<input type="submit" value="Submit" >
</form>
<div style="background-color:#CCC; width:1064PX">Showing <?=$showing?> of <?=$total?> Results</div>
<?php
$result = mysqli_query($con,$query);
$total = mysqli_num_rows($result);
echo "<table width='1064px' cellspacing='10px' >";
echo '<tr width:210px;" height="40%">';
session_start();
for ($i = 1; $row = mysqli_fetch_assoc($result); $i++) {
$name = $row["p_name"];$name = strtoupper($name);
$number = $row["p_number"];
$price = $row["p_price"];
$url = $row["p_url"];
$manufacturer = $row["p_man"];
$p_desc_link = $row["p_desc_link"];
if($_SESSION['mon'] = 'JMD')
{
$price = currency(usd,jmd,$price);
}
if($_SESSION['mon'] = 'USD')
{
$price = $row['p_price'];
}
$cur = $_SESSION['mon'];
$user = $_SESSION['user'];
echo "<td>
<form action='http://definitionxjm.com/product_page.php' method='post'>
<input type='hidden' name='inum' value='$number'>
<input type='image' src='http://www.definitionxjm.com/$url' title='More Details' alt='More Details'>
</form>
<br>
<div class='productname' ><a target='_blank' style=' color:#727172; text-decoration:none !important;' href='$p_desc_link'>$name</a></div>
<br>
<div class='productdetails'>
Manufacturer: $manufacturer<BR>
Item number : $number<br>
</div>
<br>
<div class='PRODUCTPRICE'>$cur $price</div><br><br>
<div width='210px'>
<div style='width:104px; float:left'>
<form action='http://definitionxjm.com/shopping/renderCart.php' method='post' >
<input type='hidden' name='user' value='$user'>
<input type='hidden' name='quantity' value='1'>
<input type='hidden' name='itemNum' value='$number'>
<input type='image' src='../images/ADD-TO-CART.png' width='87' height='36'>
</form>
</div>
<div style='width:104px; float:right'>
<form action='http://definitionxjm.com/product_page.php' method='post'>
<input type='hidden' name='inum' value='$number'>
<input type='image' src='../images/DETAILS.png' width='87' height='36'>
</form>
</div>
</div>
</td>
";
if (($i % 4 == 0) && ($i < $total)) {
echo '</tr><tr width:20%;" height="40%">';
}
}
echo '</tr>';
echo '</table>';
if($pages >= 1 && $page <=$pages)
{
for($x = 1; $x<= $pages; $x++)
{
echo '<a href="?page='.$x.'">'.$x.'</a> ';
}
}
?>
</div>
<?php require('../footer.php'); ?>
</body>
</html>
答案 0 :(得分:1)
您没有设置正确的偏移量。
将$start
设为$start = ($page - 1) * $perpage+1;
。