gpt4 book ai didi

php - 使用分页按类别列出项目

转载 作者:行者123 更新时间:2023-11-30 23:06:13 25 4
gpt4 key购买 nike

我有一个带有分页概念的 php 页面,用于列出数据库中的项目并列出带有字母的项目。就像点击“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\">&#171; </a>";
else
$pagination.= "<span class=\"disabled\">&#171; </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\"> &#187;</a>";
else
$pagination.= "<span class=\"disabled\">&#187;</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);
}
}

提前致谢。

最佳答案

你的 mysql 查询应该是这样的

SELECT * FROM  `your_table` WHERE  `column_name` LIKE  '$your_query%' LIMIT 0 , 10

其中 0 是您的页码 -1。

关于php - 使用分页按类别列出项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21793747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com