페이지 매김 질문이 있습니다. 이 페이지를 브라우저에로드하고 카테고리 링크를 클릭하면 첫 페이지가 제품에 제한적으로 표시되고 페이지 매김 링크는 제자리에 있지만 첫 번째 페이지로 계속 전송됩니다. 첫 번째 페이지는 어떤 페이지 매김 링크 이건간에 제로입니다. 나는 클릭한다. 나는 카테고리를 클릭 한 후 보여주기 위해 노력하고있어 제품의 나머지 부분을 보여줍니다 만약 내가
$offset=($pageNum)= $perPage;
에
$offset=($pageNum - 1) * $perPage;
을 변경할 때 이상한 일이 있습니다. 문제는 페이지 또는 어딘가에있을 수 있습니다.
여기 내 코드입니다.
<?php
$productUlList="";
error_reporting (E_ALL^E_NOTICE);
include_once "convenientglobal2localhost.php";
$result = mysql_query("SELECT * FROM category WHERE 1")or die(mysql_error());
while($rowp=mysql_fetch_array($result)){
$categoryId=$rowp['catId'];
$categoryName=$rowp['catName'];
$productUlList.='
<ul id="ul" >
<li id="lists"> <a href="'.$_SERVER['PHP_SELF'].'?category='.$categoryName.'"> '.$categoryName.' </a> </li>
</ul>';
}
?>
<?php
$msg_to_user3='';
$productList.='';
$categoryList='';
include_once "convenientglobal2localhost.php";
$perPage= 3;
if(isset($_GET['category']))
$categoryNames=$_GET['category'];
$pageNum=(isset($_GET['page']))? (int)$_GET['page']: 1;
$pages_query= mysql_query("SELECT * FROM products INNER JOIN category ON categoryName=catName WHERE categoryName='$categoryNames'");
$numrows= mysql_num_rows($pages_query);
$maxpages=ceil($numrows/$perPage);
$offset=($pageNum-1) * $perPage;
if ($offset < 0)
{
$offset = 0 ;
}
include_once "convenientglobal2localhost.php";
$results = mysql_query("SELECT * FROM products WHERE categoryName='$categoryNames' LIMIT $offset, $perPage")or die(mysql_error());
$num=mysql_num_rows($results);
if($num > 0){
while($row=mysql_fetch_array($results)){
$productId=$row['productId'];
$productName=$row['name'];
$productDescription=$row['description'];
$productPrice=$row['price'];
$productDiscountedPrice=$row['discountedPrice'];
$productStock=$row['stock'];
$productCategory=$row['categoryName'];
$categoryId=$row['catId'];
$catName=$row['catName'];
$categoryList='<table><th id="toptable"></th></table>
<table id="categorytable">
<th><img src="inventory_category_images/' . $categoryId . '.jpg" width="498px"; height="125px";/></th>
</table>';
$productList.='<table id="productoutputtable">
<tr>
<td rowspan="7" valign="top"><img style="border-style=solid; border-color:#767475; padding=; "src="inventory_images/' . $productId . '.jpg" width="150" height="135"/>
</td>
</tr>
<tr>
<td id="tablecolor" ><strong>Product</strong></td>
<td colspan="2">' . $productName . ' </td>
<td id="tablecolor"><strong>Category</strong></td>
<td>' . $productCategory . ' </td>
</tr>
<tr>
<td id="tablecolor"><strong>Description:</strong></td>
<td colspan="3">' . $productDescription . ' </td>
</tr>
<tr>
<td id="tablecolor" ><strong>Price:</strong></td>
<td>$' . $productPrice . ' </td>
</tr><tr>
<td id="tablecolor"colspan="1"><strong>Sale Price:</strong></td>
<td>$' . $productDiscountedPrice . ' </td>
<td id="tablecolor"colspan="2"><strong>In Stock </strong></td>
<td>' . $productStock . ' </td>
</tr>
</table>';
}
$self= $_SERVER['PHP_SELF'];
for($page=1; $page<=$maxpages; $page++){
if($page == $pageNum){
$nav= "$page";
}
else{
$nav= "<a href=\"$self?page=$page\">$page</a>";
}
}
if($page > 1)
{
$page=$pageNum-1;
$prev ="<a href=\"$self?page=$page\">[Prev]</a>";
$first="<a href=\"$self?page=1\">[First Page]</a>";
}
else
{
$prev= " ";
$first=" ";
}
if($pageNum < $maxPages)
{
$page=$pageNum+1;
$next ="<a href=\"$self?page=$page\">[Next]</a>";
$last="<a href=\"$self?page=$maxPages\">[Last Page]</a>";
}
else
{
$next= " ";
$last=" ";
}
$pageList.= $first. $prev. $nav. $next. $last;
}
else{
$msg_to_user3="You have no products listed.";
}
//$pageList.="";
//for($i = 0 ; $i <= $maxpages ; $i++) {
//if($i == $page) {
//$pageList.= "<B>$i</B>";
//}else{
//$pageList.= '<A HREF="?page='.$i.'">'.$i.'</A>';
//
//}
//}
?>
감사합니다.
정확히 무엇입니까? 긴 코드를 추적하는 것은 어렵습니다. – Lion
'select *'를하지 말고 mysql_num_rows()를 사용하십시오. 당신은 방금 버리고있는 디스크에서 데이터를 가져 오는 데 많은 노력을 낭비해야합니다. 'select count (*)'를 사용하고 그 대신에 하나의 행 결과를 가져옵니다. –
FYI, 당신은 ** SQL injection에 대해 ** 활짝 열려 ** 당신이 이미 해킹 당했다면 ** 해킹 당할 것입니다. 이 문제를 완전히 피하기 위해 준비된 쿼리를 PDO와 함께 사용하는 방법을 배웁니다. – Brad