2014-02-15 80 views
1

我有一個分頁概念的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); 
     } 
    } 

在此先感謝。

+1

...??你有嘗試過什麼嗎? –

+0

是的,我使用腳本與AJAX – viji

+0

當你在這裏問的時候,你最好發佈你的代碼,如果你想得到你的答案。 –

回答

0

你的MySQL查詢將會像

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

其中0將是你的頁面數-1。

+0

我使用它,但我的問題是在PHP腳本,這是在我的問題編輯 – viji