大家好,我对 mysql 和 php 很陌生。我有一个产品库,我设法将它放在一起并复制其他人的代码来对记录进行分页。画廊有两张桌子;一个保存数据,例如:productID、title、online ......和 productTypeID,它是 productType 的一个关系字段。现在我想当我单击图像以传递两个参数 productID 和 productTypeID 并在详细页面中创建一个分页,该分页按 productTypeID 对所有记录进行分组,但转到与参数上传递的 productID 相等的特定记录。
我设法通过 productTypeID 进行分页查询,但它只会转到数组上的第一条记录。这是我的代码,请帮忙。
<?php
if (isset($_GET['id'])) {
$id = $_GET['id'];
$query_productCount= "SELECT * FROM products WHERE productID ='$id'";
$productCount= mysql_query($query_recipeMenu, $connection) or die(mysql_error());
$row_productCount= mysql_fetch_assoc($productCount);
}
if (isset($_GET['cat'])) {
$cat = $_GET['cat'];
}
//check for a page number. If not, set it to page 1
if (!(isset($_GET['pagenum']))){
$pagenum = 1;
}else{
$pagenum = $_GET['pagenum'];
}
//query for record count to setup pagination
$data = mysql_query("SELECT * FROM products WHERE productTypeID='$cat'");
$rows = mysql_num_rows($data);
//number of record per page
$page_rows = 1;
//get the last page number
$last = ceil($rows/$page_rows);
//make sure the page number isn't below one, or more than last page num
if ($pagenum < 1){
$pagenum = 1;
}elseif ($pagenum > $last){
$pagenum = $last;
}
//Set the range to display in query
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
//get all of the record
$dynamicList = "";
$sql = mysql_query("SELECT * FROM products WHERE productTypeID='$cat' $max");
//check for record
$productCount = mysql_num_rows($sql);
if ($productCount > 0){
while($row = mysql_fetch_array($sql)){
$productID = $id;
$productName = $row["productName"];
$largeImage = $row["largeImage"];
$productDescription = $row["productDescription"];
$dynamicList .= '
<div>
<h3>'.$productName.'</h3>
<div><a href="javascript:history.go(-1)"><img src="images/productImages/'.$largeImage.'" alt="'.$productName.'" width="" /></a></div>
<p">'.strip_tags(nl2br($productDescription), "<b><br><p><a>").'</p>
</div>
';
}
}else{
$dynamicList = "<p>Sorry there are no products under this category</p>";
}