dongyou6847 2016-05-03 11:56
浏览 24

$ _POST'提交'[重复]内的分页

This question is an exact duplicate of:

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\">
";
  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>";;

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

</div>
  • 写回答

1条回答 默认 最新

  • dongsou3041 2016-05-03 12:05
    关注

    Should be,

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

报告相同问题?

悬赏问题

  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私