2016-07-08 2 views
-1

동적 테이블을 만들 때 페이지 당 레코드에 대해 사용자 정의 선택 옵션을 갖고 싶습니다. 나는 사이트에서 볼하지만 페이지선택 옵션에서 페이지 당 페이지 매김 레코드

에 대한 선택 옵션이 없습니다

내 생각이 같다 :

나는 PHP 태그에 $per_page을 변경하고자하지만 나에게 내가 사용하는 경우 오류를 제공합니다 도움

<form method="GET"> 
<select id="records" name="records"> 
      <option value="10">10</option> 
       <option value="20">20</option> 
      <option value="30">30</option> 
      <option value="40">Mostra tutti</option> 
      </select><li> 
      <li><input type = "submit" class = button2 name = "btnsubmit"></li> 
      </form> 
</ul></nav> 

<?php 
$page_name="admin_list.php"; 
$per_page = 10 ; 

     if ($result = $con->query("SELECT * FROM clienti WHERE utenza =1 OR utenza =0 ORDER BY es_insegna_esercizio")) 
     { 

     if ($result->num_rows != 0) 
     { 
     $total_results = $result->num_rows; 
     // ceil() returns the next highest integer value by rounding up value if necessary 

     $total_pages = ceil($total_results/$per_page); 

     // check if the 'page' variable is set in the URL (ex: view-paginated.php?page=1) 
     if (isset($_GET['page']) && is_numeric($_GET['page'])) 
     { 
     $show_page = $_GET['page']; 

     // make sure the $show_page value is valid 
     if ($show_page > 0 && $show_page <= $total_pages) 
     { 
     $start = ($show_page -1) * $per_page; 
     $end = $start + $per_page; 
     } 
     else 
     { 
     // error - show first set of results 
     $start = 0; 
     $end = $per_page; 
     } 
     } 
     else 
     { 
     // if page isn't set, show first set of results 
     $start = 0; 
     $end = $per_page; 
     } 

     echo "<table id='my_table' class='tables' name ='tablename'>"; 

      echo " 

      <thead><tr> 
        <th></th> 
        <th> 
       <input type = checkbox > 
        </th> 
        <th>Azienda</th> 
        <th>Utente</th> 
        <th>Cognome</th> 

      </tr></thead> 
       " ; 

      // loop through results of database query, displaying them in the table 
      for ($i = $start; $i < $end; $i++){ 
      // make sure that PHP doesn't try to show results that don't exist 
      if ($i == $total_results) { break; } 
      // find specific row 
      $result->data_seek($i); 
      $row = $result->fetch_row(); 
      // echo out the contents of each row into a table 
      echo "<tr>"; 

       echo '<td><img src ="images/edit_icon.png"class = "autoResizeImage" onclick="JavaScript:newPopup(\'admin_edit.php?id='.$row['0'].'\')" /></td>'; 
       echo '<td><input type=checkbox name=chk[] class= chk-box value='.$row[0].'/></td>'; 
       echo '<td>' . $row[14] . '</td>'; 
       echo '<td>' . $row[2]. '</td>'; 
       echo '<td>' . $row[3] . '</td>'; 
       echo '<td>' . $row[4] . '</td>'; 

       echo "</tr>"; 
      } 
      // close table> 
      echo "</table></form>"; 
     } 
     else{ 
     echo "No results to display!"; 
     } 
     } 
     // error with the query 
     else{ 
     echo "Error: " . $con->error; 
     } 
    echo "<p> 
<b>View Page: </b>"; 
    for ($i = 1; $i <= $total_pages; $i++){ 
    if (isset($_GET['page']) && $_GET['page'] == $i){ 
    echo $i; 
    } 
    else{ 
    echo "<a href='admin_list.php?page=$i'>$i</a> "; 
    } 
    } 

    echo "</p>"; 
    // close database connection 
     $con->close(); 

?> 
</form> 

</div> 

답변

0

에 대한 $_GET$_POST .. 덕분에 당신은 형식과 제출 된 값을 얻을 것이다 PHP 코드가 필요합니다. 이 코드를 요소에 밖으로

<form method="GET"> 
     <select name="records"> 
      <option value="1">1</option> 
      <option value="2">2</option> 
      <option value="3" selected>3</option> 
      <option value="4">4</option> 
     </select> 
     <input type="submit" name="submit" value="Submit"> 
</form> 
<?php 
     $per_page = 30 ; 

     if(isset($_GET['submit']) && !empty($_GET['records']) && preg_match("/^[0-9]+$/", $_GET['records'])) { 
     /* Is the form submitted + is the records set + is the records an integer*/ 
      $per_page = $_GET['records']; 
     } 

     if($result = $con->query("SELECT * FROM clienti WHERE utenza = 1 OR utenza = 0 ORDER BY es_insegna_esercizio")) { 
      if($result->num_rows != 0) { 
        $total_results = $result->num_rows; // How many records do we have? 
        $total_pages = ceil($total_results/$per_page); // How many pages do we have? 

        if(!empty($_GET['page']) && preg_match("/^[0-9]+$/", $_GET['page']) && $_GET['page'] <= $total_pages) { 
        /* is the page set + is it an integer + is it <= of total pages*/ 
         $show_page = $_GET['page']; 
         $start = ($show_page -1) * $per_page; 
         $end = $start + $per_page; 
        } else { 
         $start = 0; 
         $end = $per_page; 
        } 
      } 
     } 
당신은 단지 추가해야
+0

옵션이 작동하지만 페이지 번호를 클릭하면 결과가 행당 30 개로 돌아갑니다. – rcpd

+0

나는 당신이 무슨 말을하는지 잘 모르겠습니다. 조금 더 나은 문제를 설명 할 수 있습니까? – b0ne

+0

옵션이 작동하고 행 개수가 변경되지만 다음 페이지 (예 : 1 [2] 3 4 5)를 클릭하면 5. 행 수가 선택한 값 대신 30 개의 페이지 당 값을 반환합니다. thanks – rcpd

0
<select id="records" name="records"> 
     <option value="10">10</option> 
     <option value="20">20</option> 
     <option selected value="30">30</option> 
     <option value="40">40</option> 
     </select> 
     <input type = "submit" name = "record"> 

$per_page = 30 ; 

if(isset($_GET["records"]) && $_GET["records"] > 0) 
{ 
    $per_page = $_GET["records"] ;  
} 


    if ($result = $con->query("SELECT * FROM clienti WHERE utenza =1 OR utenza =0 ORDER BY es_insegna_esercizio")) 
    { 

    if ($result->num_rows != 0) 
    { 
    $total_results = $result->num_rows; 
    // ceil() returns the next highest integer value by rounding up value if necessary 

    $total_pages = ceil($total_results/$per_page); 

    // check if the 'page' variable is set in the URL (ex: view-paginated.php?page=1) 
    if (isset($_GET['page']) && is_numeric($_GET['page'])) 
    { 
    $show_page = $_GET['page']; 

    // make sure the $show_page value is valid 
    if ($show_page > 0 && $show_page <= $total_pages) 
    { 
    $start = ($show_page -1) * $per_page; 
    $end = $start + $per_page; 
    } 
    else 
    { 
    // error - show first set of results 
    $start = 0; 
    $end = $per_page; 
    } 
    } 
    else 
    { 
    // if page isn't set, show first set of results 
    $start = 0; 
    $end = $per_page; 

'이름'속성을보십시오. '레코드'조건을 추가하십시오. 친절하게 이것을 사용하십시오. 문제가 해결 될 것입니다.

또한 'POST'방법을 사용하는 경우 조건에 $ _POST 메소드를 사용하십시오.

+0

감사하지만, 그것의 페이지 수를 변경 나던하는 오류는 점점 – rcpd

+0

를 작동하지 않는 것은 – Hardik

+0

:( – rcpd

관련 문제