2014-01-28 174 views
0

我的代碼如下分頁不工作

if(isset($_POST['find_x']) || isset($_POST['find_y'])){ ?> 

<table style="font-family:Tahoma, Geneva, sans-serif; font-size:12px" width="100%" border="0" cellspacing="2" cellpadding="2"> 
<tr bgcolor="#FFFFFF" ><td colspan="11" align="left">Total Repairs: <? $count=mysql_num_rows($result); echo "<b style='color:#F00;'>".$count."</b>"; ?></td></tr> 
    <tr class="tableDetail" style="background-image:url(../images/tblHeaderBack.jpg);" > 
    <td align="center">Customer Name</td> 
    <td align="center">Serial #</td> 
    <td align="center">Ack No</td> 
    <td align="center">RAF Date</td> 
    <td align="center">Phone No</td> 
    <td align="center">Email</td> 
    <td align="center">Product Details</td> 
    <td align="center">Repair Status</td> 
    <td align="center">Location Name</td> 
    <td align="center">Physical Location</td> 
    <td align="center">Aging</td> 
    <td align="center">Assigned To</td> 
    <td align="center">Created By</td> 
    </tr> 

<? 

    $adjacents = 1; 

    /* 
     First get total number of rows in data table. 
     If you have a WHERE clause in your query, make sure you mirror it here. 
    */ 
    $query = "select count(*) as num from tblRepairQueue where repairStatus!='Closed and Complete' "; 
    $total_pages = mysql_fetch_array(mysql_query($query)); 
    $total_pages = $total_pages[num]; 

    /* Setup vars for query. */ 
    $targetpage = "lookup1.php"; //your file name (the name of this file) 
    $limit =10;         //how many items to show per page 
    $page = $_POST['page']; 

    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 

    /* Get data. */ 

    $sql = "select * from tblRepairQueue where repairStatus!='Closed and Complete' order by savedAt DESC LIMIT $start, $limit"; 
    $result = mysql_query($sql); 

    /* 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 

    /* 
     Now we apply our rules and draw the pagination object. 
     We're actually saving the code to a variable in case we want to draw it more than once. 
    */ 
    $pagination = ""; 
    if($lastpage > 1) 
    { 
     $pagination .= "<div class=\"pagination\">"; 
     //previous button 
     if ($page > 1) 
      $pagination.= "<a href=\"$targetpage?page=$prev\">previous</a>"; 
     else 
      $pagination.= "<span class=\"disabled\">previous</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 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 href=\"$targetpage?page=$counter\">$counter</a>";     
       } 
       $pagination.= "..."; 
       $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; 
       $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";  
      } 
      //in middle; hide some front and some back 
      elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) 
      { 
       $pagination.= "<a href=\"$targetpage?page=1\">1</a>"; 
       $pagination.= "<a 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 href=\"$targetpage?page=$counter\">$counter</a>";     
       } 
       $pagination.= "..."; 
       $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; 
       $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";  
      } 
      //close to end; only hide early pages 
      else 
      { 
       $pagination.= "<a href=\"$targetpage?page=1\">1</a>"; 
       $pagination.= "<a 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 href=\"$targetpage?page=$counter\">$counter</a>";     
       } 
      } 
     } 

     //next button 
     if ($page < $counter - 1) 
      $pagination.= "<a href=\"$targetpage?page=$next\">next </a>"; 
     else 
      $pagination.= "<span class=\"disabled\">next </span>"; 
     $pagination.= "</div>\n";  
    } 

     while($row = mysql_fetch_array($result)) 
     { ?> 
<tr id="<?php $row['serialNo'] ?>" align="center" valign="top" style="background-color:#FFF"> 
    <td ><?=$row['customerName']?></td> 
    <td ><?=$row['serialNo']?></td> 
    <td ><?=$row['ackNo']?></td> 
    <td ><?=$row['savedAt']?></td> 
    <td ><?=$details['phoneNo']?></td> 
    <td ><?=$details['emailId']?></td> 
    <td ><?=$row['productDescription']?></td> 
    <td nowrap="nowrap"><?=$row['repairStatus']?></td> 
     <td ><?=$row['location']?></td> 
     <td ><?=$row['phyLocation']?></td> 
     <td ><? echo "<b>".$days."</b><span style='color:#F00'>d</span>&nbsp;<b>".$hours."</b><span style='color:#F00'>hr</span>&nbsp;<b>".$mins."</b><span style='color:#F00'>m</span>";?></td> 
     <td ><?=$row['assignedTo']?></td> 
     <td ><?=$row['createdUser']?></td> 
    </tr> 

    <? } ?> 
<tr> 
<td align="center" colspan="9"><?=$pagination?> </td></tr> 
</table> 

<? } 
    ?> 

,當我在尋找按鈕分頁單擊來,只有第一頁,但如果我接下來的頁面上點擊或任何其數字不working.pagination不

if(isset($_POST['find_x']) || isset($_POST['find_y'])){ ?> 

,但您使用paginati GET方法:如果我點擊下一個button..can誰能幫我找到解決方案

+0

這是件好事,你粘貼完整的代碼。但是,如果你指定特定的代碼塊會更好。我無法在代碼中找到單個isset – Roopendra

+0

@Roopendra我只粘貼了部分代碼..代碼仍然較大 – namratha

+1

「不工作」是什麼意思? – Hardy

回答

1

你檢查在POST方法變量工作on,所以post變量不可用,並且該子句總是爲false。

更改您的搜索結果以使用$ _GET params。因此,在你的搜索形式:

<form method="get" action="lookup1.php"> 

然後檢查得到的變量,而不是職位:

​​

,並添加find_x和find_y像分頁鏈接:

"<a href=\"$targetpage?page=$counter&find_x=$find_x\">$counter</a>" 
+0

我用分頁內POST方法..我的猜測是因爲isset它不工作.. – namratha

+0

你不能設置帖子變量與錨鏈接。您必須使用表單來發布數據。我在你的代碼中看不到任何表單。它第一次工作,因爲你發佈某種形式的數據,然後這兩個變量中的另一個可用。 – Hardy

+0

m使用表單只與方法post – namratha