分页不会在第二页上工作,所以 [英] pagination doenst work for second page and so
本文介绍了分页不会在第二页上工作,所以的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在写一个分页,因为我是php新手,但我有一个问题.当在代码中为变量赋常量时,分页工作正常,因为我通过客户端将其传递给它,所以它只会加载第一页,而第二页和其他页将不会显示,
怎么了?
这是代码
Hi all,
I am writing a pagination as I am new to php I have a problem in that. When give a constant to a variable inside the code the pagination works properly wen I pass it via the client side it just loads the first page and the second and other pages will not appear,
What is wrong with that?
here is the code
$sqlcount=("SELECT * FROM job_results where Title LIKE '%$kw%'");
$row_result = mysql_query($sqlcount) or die(mysql_error());
$rowspage = mysql_num_rows($row_result);
$numrows =$rowspage;
// number of rows to show per page
$rowsperpage = 10;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);
// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
} // end if
// if current page is greater than total pages...
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
$sqlcount=("SELECT * FROM job_results where Title LIKE '%$kw%' LIMIT $offset, $rowsperpage");
$row_result = mysql_query($sqlcount) or die(mysql_error());
//echo $sqlcount;
//end of pagination
while($row = mysql_fetch_array($row_result, MYSQL_ASSOC)){
echo(...);
}
<pre lang="xml">$range = 3;
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
} // end if
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo " [<b>$x</b>] ";
// if not current page...
} else {
// make it a link
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
// echo forward link for lastpage
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
} // end if
/****** end build pagination links ******/
推荐答案
sqlcount =( 选择* FROM job_results,其中标题为'%
sqlcount=("SELECT * FROM job_results where Title LIKE '%
kw%'");
kw%'");
row_result = mysql_query(
row_result = mysql_query(
这篇关于分页不会在第二页上工作,所以的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文