选择选项中每页的分页记录

时间:2016-07-08 09:59:33

标签: php pagination

我正在创建一个动态表,我希望每页记录有自定义选择选项。我在一个网站上查看,但它没有选择页面

我的想法是这样的:

我想将 $per_page 更改为PHP标记,但如果我使用$_GET$_POST,则会出错...感谢您的帮助

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

2 个答案:

答案 0 :(得分:0)

您需要一个表单和一个PHP代码来获取提交的值。试试这段代码

 SELECT SCN_TO_TIMESTAMP(MAX(ora_rowscn)) from export01;

答案 1 :(得分: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;

您只需在元素中添加'name'属性即可。并为“记录”添加条件。请使用这个。您的问题将得到解决。

另外,如果使用'POST'方法,则在条件中使用$ _POST方法。