Php 这个
改变Php 这个,php,mysql,sql,pdo,Php,Mysql,Sql,Pdo,改变 if ($pagenum < 1) { $pagenum = 1; } else if ($pagenum > $last) { $pagenum = $last; } 如果未设置$\u GET['page'],我将运算符与isset()一起使用,以确保页面默认为1。(即在第一次加载页面时) 解释 如果设置了$\u GET['page'],$page=$\u GET['page'] 如果未设置$\u GET['page'],$page=1我将运算符
if ($pagenum < 1)
{
$pagenum = 1;
}
else if ($pagenum > $last)
{
$pagenum = $last;
}
如果未设置$\u GET['page']
,我将运算符与isset()
一起使用,以确保页面默认为1。(即在第一次加载页面时)
解释
如果设置了$\u GET['page']
,$page=$\u GET['page']
如果未设置$\u GET['page']
,$page=1
我将运算符与isset()
一起使用,以确保未设置$\u GET['page']
时页面默认为1。(即在第一次加载页面时)
解释
如果设置了$\u GET['page']
,$page=$\u GET['page']
如果未设置$\u GET['page']
,$page=1
我将运算符与isset()
一起使用,以确保未设置$\u GET['page']
时页面默认为1。(即在第一次加载页面时)
解释
如果设置了$\u GET['page']
,$page=$\u GET['page']
如果未设置$\u GET['page']
,$page=1
我将运算符与isset()
一起使用,以确保未设置$\u GET['page']
时页面默认为1。(即在第一次加载页面时)
解释
如果设置了$\u GET['page']
,$page=$\u GET['page']
如果未设置
$\u GET['page']
,$page=1
您可以回显实际查询吗?您可以回显实际查询吗?您可以回显实际查询吗?页面应为1,因为调用函数时未设置$\u GET[“page”]。什么是$count值和$last to spesific?页面应为1,如$\u GET[调用函数时未设置“page”]。什么是$count value和$last to spesific?页面应为1,因为调用函数时未设置$u GET[“page”]。什么是$count value和$last to spesific?页面应为1,因为调用函数时未设置$u GET[“page”]。什么是$count value和$last to be spesific?
function GetItemSubCategory($connection,$num,$page,$category,$subcategory)
{
//Results per page
$pagerows=10;
//Tells us the last page number
$last=ceil($num/$pagerows);
// This sets the range of rows to query for the chosen $page
$limit = 'LIMIT ' .($page - 1) * $pagerows .',' .$pagerows;
//Grabbing one page worth of results due to the use of $limit, results are ordered by BusinessName in descending order.
$getpageresult=$connection->prepare("SELECT `ItemID`,`ItemName`,`ItemDesc`,`ItemPrice`,`ItemDP`,`EditDate`,`ItemCategory`,`ItemSubCategory` FROM `Items` WHERE `ItemCategory` =:itemcat AND `ItemSubCategory`=:itemsubcat ORDER BY `EditDate` DESC $limit");
$getpageresult->bindValue(":itemcat",$category);
$getpageresult->bindValue(":itemsubcat",$subcategory);
$getpageresult->execute();
//Initialises the $result variable to display the results of the query
$result = '';
while($row = $getpageresult->fetch(PDO::FETCH_ASSOC)){
$itemid = $row["ItemID"];
$itemname = $row["ItemName"];
$itemdesc=$row["ItemDesc"];
$itemprice=$row["ItemPrice"];
$itemdp=$row["ItemDP"];
$editdate=$row['EditDate'];
$itemcategory=$row["ItemCategory"];
$result .= "<div id='SearchResult' class='SearchResult' >
<div class='SearchResultTop'><span class='SearchResultName'><a href='#'>$itemname</a></span><span class='SearchResultPrice'>$ $itemprice</span></div>
<div class='SearchResultMid'><a href='#' class='SearchResultImg'><img height=130px width=130px src=\"$itemdp\" alt=\"$itemname\"></a><div class='SearchResultDesc'>$itemdesc</div></div>
<div class='SearchResultBtm'><span class='SearchResultEditDate'>$editdate</span></div>
</div>";
}
return $result;
}
//Additional code above which sets up the view,cat and subcat variable
elseif($view =="items")
{
//Grabs total number of items and assigns it to the $count variable
$count=GetItemCountSubCategory($cxn,$cat,$subcat);
//Sets number of results on a page
$pagerows=10;
//Tells us the last page number
$last=ceil($count/$pagerows);
//Checks if the $_GET variable is present and sets the page to 1 if it is not
if(!isset($_GET['page']))
{
$pagenum = 1;
}
else
{
$pagenum = preg_replace('#[^0-9]#', '', $_GET['page']);
}
// This makes sure the page number isn't below 1, or more than our $last page
if ($pagenum < 1)
{
$pagenum = 1;
}
else if ($pagenum > $last)
{
$pagenum = $last;
}
$pagecounter = "Page <b>$pagenum</b> of <b>$last</b>";
$result=GetItemSubCategory($cxn,$count,$pagenum,$cat,$subcat);
$pagination=Pagination($cxn,$count,$pagenum,$view);
}
//Results per page
$pagerows=10;
//Tells us the last page number
$last=ceil($num/$pagerows);
// This sets the range of rows to query for the chosen $page
$limit = ($page - 1) * $pagerows;
$getpageresult=$connection->prepare("SELECT `ItemID`,`ItemName`,`ItemDesc`,`ItemPrice`,`ItemDP`,`EditDate`,`ItemCategory`,`ItemSubCategory` FROM `Items` WHERE `ItemCategory` =:itemcat AND `ItemSubCategory`=:itemsubcat ORDER BY `EditDate` DESC limit :limit, :offset");
$getpageresult->bindValue(":itemcat",$category);
$getpageresult->bindValue(":itemsubcat",$subcategory);
$getpageresult->bindValue(":limit", $limit);
$getpageresult->bindValue(":offset", $pagerows);
$limit = 'LIMIT ' .($page - 1) * $pagerows .',' .$pagerows;
if ($pagenum < 1)
{
$pagenum = 1;
}
else if ($pagenum > $last)
{
$pagenum = $last;
}
if ($pagenum > $last)
{
$pagenum = $last;
}
if ($pagenum < 1)
{
$pagenum = 1;
}
//change
$last=ceil($count/$pagerows);
//to
$last=$count * $pagerows;
$page = isset($_GET['page']) ? $_GET['page'] : '1';