使用isset $ _GET href链接的未定义索引

时间:2017-02-10 00:33:49

标签: php mysql pagination get

我正在进行非常简单的分页,即使有了isset,我也要

  

注意:未定义的索引:第45行的页面

。我知道undefine索引是什么,但我不知道如何在此代码中修复它,因为变量页面是在href中触发的。

table.php

<?php
$perpage=3;
if(isset($_GET['page'])){
    $page=$_GET['page'];
}
else{
    $page=1;
}
$offset=($_GET['page']-1)*$perpage;
$sql="SELECT* FROM `companystructures` LIMIT ".$offset.",".$perpage."";
$result=mysqli_query($db,$sql);
?>
    <table id="myTable" class="rwd-table table table-striped table-hover tablesorter" >

  <tr>
      <th>ID</th>
    <th>Name</th>
      <th>Description</th>
        <th>Type</th>
    <th>Address</th>
    <th>Country</th>
        <th>Time Zone</th>
  </tr>

  <?php while($company=mysqli_fetch_array($result)){ ?>
  <tr>
      <td data-th="ID"><?=$company['id'];?></a></td>
      <td data-th="Name"><?=$company['title'];?></td>
    <td data-th="Description"><?=$company['description'];?></td>
    <td data-th="Type"><?=$company['type'];?></td>
    <td data-th="Address"><?=$company['address'];?></td>
    <td data-th="Country"><?=$company['country'];?></td>
    <td data-th="Time Zone"><?=$company['timezone'];?></td>
  </tr>

    <?php };?>

</table>


      <div class='col-md-6 pull-right'>
<!-- Pagination -->
            <?php
$sql="SELECT * FROM `companystructures`";
$result=mysqli_query($db,$sql);
$total_rows=mysqli_num_rows($result);
$total_pages=ceil($total_rows/$perpage);
echo "<a href='home.php?page=1'>First</a>";
echo "<span style='margin:5px;'>";
for($i=1;$i<=$total_pages;$i++){
echo "<a href='home.php?page=$i'>$i</a>";
echo "<span style='margin:5px;'>";
}
echo "<a href='index.php?page=$total_pages'>last</a>";
?>

        </div>

0 个答案:

没有答案