分页内$ _POST'提交' [英] pagination within a $_POST 'submit'

查看:141
本文介绍了分页内$ _POST'提交'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我选择一个类别并点击提交按钮时,我的分页显示了我的SQL语句检索到的记录数量所需的正确数量的页面。然而,当我点击页面2例如页面刷新和数据不再显示,而不是显示下一页,它只是返回显示类别下拉框和搜索按钮。

when i choose a category and hit the submit button my pagination shows the correct amount of pages needed for the amount of records my SQL statment has retrieved. however when i click page 2 for example the page refreshes and the data is not shown anymore instead of showing the next page it just returns to show the category drop down box and the search button.

if(isset($_POST['search'])) {

  $filmCategory = isset($_REQUEST['filmCategory']) ? $_REQUEST['filmCategory'] : null;

  if (empty($filmCategory)) {
    $whereclause = '';
  }else {
    $whereclause = "where c.category_id = '$filmCategory'";
  }

  require_once('functions.php');

//user input
    $page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
    $perPage = isset($_GET['per-page']) && $_GET['per-page'] <=15 ? (int)$_GET['per_page'] : 10;

 //positioning
$start = ($page > 1) ? ($page * $perPage) - $perPage : 0;

//query 
  $filmSQL =  $db->prepare("SELECT SQL_CALC_FOUND_ROWS  f.title, f.description, f.release_year, c.name,
                   f.rating, f.last_update
            from nfc_film f
            inner join nfc_film_category fc
            on f.film_id = fc.film_id
            inner join nfc_category c
            on fc.category_id = c.category_id
            $whereclause
            LIMIT {$start}, {$perPage}");

// execute the query and get the title, description, release year, name, rating and last update of film
  $filmSQL->execute();

//echo the table with the titles and correct data from SQL
  echo "<table border=\"1\">\n";
  echo "<tr><th>Title</th><th>Description</th><th>Release Year</th><th>Category</th><th>Rating</th><th>Last Update</th></tr>";

  while ($filmInfo = $filmSQL->fetchObject()) {

    $upperLower= upperFirst(lowercase($filmInfo->title));
      $uLDescription= firstUpper(lowercase($filmInfo->description));
      $noChar = substr($uLDescription,0,100).'...';
      echo "<form action='filmInfo.php' method='get'>";
    echo "<tr>
            <td><input type='text' name='filmInfo' value='{$upperLower}'</td>
            <td><p>$noChar.</p></td>
            <td>{$filmInfo->release_year}</td>
            <td>{$filmInfo->name}</td>
            <td>{$filmInfo->rating}</td>
            <td>{$filmInfo->last_update}</td>
            <td><input type='submit' value='Film Details' </td>
          </tr>";
    echo" </form>";
  }
  echo "</table>";;

上面的所有内容都可以正常工作,但是当我选择页面2时,例如页面刷新和所有数据消失

so everything above works fine but then when i choose page 2 for example the page refreshes and all data disappears

    $total = $db->query("SELECT FOUND_ROWS() AS total")->fetch()['total'];
//use CEIL to round up the pages so here are no pages with decimals
    $pages = ceil($total / $perPage);

    for($x = 1; $x <= $pages; $x++):;
    echo"<div id='pagination'>

                <a href='?page=$x'>$x</a>

            </div>";
    endfor;
}
?>

我希望它显示记录的下一页,但我不能让它工作:(

i want it to show the next page of records but i cant get it to work :(

推荐答案

应该是,

Should be,

//positioning
$start = isset($_GET['page']) && (int)$_GET['page'] > 1 ? ($_GET['page'] - 1) * $perPage : 0;

这篇关于分页内$ _POST'提交'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆