我有一个带有分页概念的php页面,用于列出来自DB的项目,并列出带有字母的项目。就像点击“a”一样,显示名称以字母“a”开头,限制为10,剩下的应该出现在下一页。如果未选择字母,则显示所有项目的分页。我试过了,但分页和类别列表是分开工作的。
$alpha='';
if(isset($_REQUEST['alphabet_let']))
{
$alpha=$_REQUEST['alphabet_let'];
}
if(isset($_REQUEST['flag']))
{
$flag = $_REQUEST['flag'];
}
?>
<div class='cc' listTyp="<?php echo $_POST['listTyp'];?>" catId="<?php echo $_POST['catId'];?>" alpha=<?php echo $alpha;?>>
<?php $objOrg= new mysql_profile();
$tbl_name="profile_organization";
$adjacents = 3;
if($_POST['listTyp']=="mul")
{
$arrOrg= $objOrg->select_admin_profileorgs(0,0,'','',$_POST['catId']);
if($alpha!="")
{
$arrOrg= $objOrg->select_admin_profileorgs(0,0,$alpha,'',$_POST['catId']);
}
}
else
{
$arrOrg= $objOrg->select_admin_profileorgs(0,$_POST['catId'],'','','');
if($alpha!="")
{
$arrOrg= $objOrg->select_admin_profileorgs(0,$_POST['catId'],$alpha,'','');
}if($flag !=''){
$arrOrg= $objOrg->select_admin_profileorgs(0,$_POST['catId'],'','','','','','','','',$flag);
}
}
$total_pages= count($arrOrg);
if($alpha!=""){
$gsts=$_REQUEST['alphabet_let'];
$targetpage = "catID.php?alphabet_let=$gsts";
}else{
$targetpage = "catID.php";
}
//your file name (the name of this file)
$limit =10; //how many items to show per page
$page = 1;
if(isset($_REQUEST['page']))
{
$page = $_REQUEST['page'];
}
if(isset($_REQUEST['page']) && isset($_REQUEST['alphabet_let']))
{
$page = $_REQUEST['page'];
echo $let = $_REQUEST['alphabet_let'];
}
if($page)
$start = ($page - 1) * $limit; //first item to display on this page
else
$start = 0; //if no page var is given, set start to 0
/* Setup page vars for display. */
if ($page == 0) $page = 1; //if no page var is given, default to 1.
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
$lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1; //last page minus 1
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class=\"pagination\">";
//previous button
if ($page > 1)
$pagination.= "<a class='prepage' href=\"$targetpage&page=$prev\">« </a>";
else
$pagination.= "<span class=\"disabled\">« </span>";
//pages
if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a class='pagee' href=\"$targetpage&page=$counter\">$counter</a>";
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a class='pagee' href=\"$targetpage&page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a class='pagee' href=\"$targetpage&page=$lpm1\">$lpm1</a>";
$pagination.= "<a class='pagee' href=\"$targetpage&page=$lastpage\">$lastpage</a>";
}
//in middle; hide some front and some back
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a class='pagee' href=\"$targetpage&page=1\">1</a>";
$pagination.= "<a class='pagee' href=\"$targetpage&page=2\">2</a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a class='pagee' href=\"$targetpage&page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a class='pagee' href=\"$targetpage&page=$lpm1\">$lpm1</a>";
$pagination.= "<a class='pagee' href=\"$targetpage&page=$lastpage\">$lastpage</a>";
}
//close to end; only hide early pages
else
{
$pagination.= "<a class='pagee' href=\"$targetpage&page=1\">1</a>";
$pagination.= "<a class='pagee' href=\"$targetpage&page=2\">2</a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a class='pagee' href=\"$targetpage&page=$counter\">$counter</a>";
}
}
}
//next button
if ($page < $counter - 1)
$pagination.= "<a class='nxtpage' href=\"$targetpage&page=$next\"> »</a>";
else
$pagination.= "<span class=\"disabled\">»</span>";
$pagination.= "</div>\n";
}
?>
<?php
$objOrg= new mysql_profile();
$objLocn = new mysql_ix_location();
$arrOrg = array();
if($_POST['listTyp']=="mul")
{
$arrOrg= $objOrg->select_admin_ix_profileorgs(0,0,'',$strlimit,$_POST['catId'],'',0,'order');
if($alpha!="")
{
$arrOrg= $objOrg->select_admin_ix_profileorgs(0,0,$alpha,$strlimit,$_POST['catId'],'',0,'order');
}
}
else
{
$arrOrg= $objOrg->select_admin_ix_profileorgs(0,$_POST['catId'],'',$strlimit,'','',0,'order');
if($alpha!="")
{
$arrOrg= $objOrg->select_admin_ix_profileorgs(0,$_POST['catId'],$alpha,$strlimit,'','',0,'order');
}if($flag !=''){
$arrOrg= $objOrg->select_admin_ix_profileorgs(0,$_POST['catId'],'',$strlimit,'','',0,'order','','',$flag);
}
}
提前致谢。
答案 0 :(得分:0)
你的mysql查询就像
SELECT * FROM `your_table` WHERE `column_name` LIKE '$your_query%' LIMIT 0 , 10
其中0将是您的页码-1。