dongshao5573 2015-04-03 18:43
浏览 15
已采纳

如何在页面不存在时为留言簿制作404

I am using a guestbook with pagination. So in the url is something like: http://example.com/guestbook/guestbook.php?page=6 When typing a page in the url which does not exist yet, (for instance page=9999) he gives me the echo: "Be the first to write in the Guestbook" How can i put a 404 to all those pages which do not exist yet?

 if (mysqli_num_rows($results) != 0) { // if DB is not empty

// display records
while ($row = mysqli_fetch_array($results))
{ ?>
    <div class="wrapper">

        <div class="velden"> <!-- for styling echos; CSS -->
            <div class="header">
                <div class="naam"><?php echo htmlspecialchars($row['name'], ENT_QUOTES, UTF-8, true); ?></div> <!-- echo naam-->
                <div class="email"><?php echo htmlspecialchars($row['email'], ENT_QUOTES, UTF-8, true); ?></div> <!-- echo email-->
                <div class="tijd"><?php echo $row['datetime']; ?></div> <!-- echo datum en tijd-->

            </div>

            <div class="bericht"><?php echo htmlspecialchars($row['message'], ENT_QUOTES, UTF-8, true); ?></div> <!-- echo bericht-->

        </div> <!-- end velden -->

<?php } ?>


        <?php echo pagination($statement,$per_page,$page,$url='?'); ?>
    </div> 


<?php } else { // DB is emtpy
 echo "Be the first to write in the Guestbook";
}
  • 写回答

2条回答 默认 最新

  • douhui4699 2015-04-03 18:47
    关注

    Something like this may help:

    else { // DB is emtpy
        if (isset($_GET['page']]) {
            echo 'Page 404';
        } else {
            echo "Be the first to write in the Guestbook";
        }
    }
    

    This extension is although not very nice I would say. You could use your code which you have before the part you posted (where you parse data for mysql query) to achieve the same thing and have the clearer code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line