上一个/下一个按钮? [英] Previous/next Buttons?

查看:122
本文介绍了上一个/下一个按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想输入论坛的上一个和下一个按钮,因为在论坛时间过长之后,它超过了背景图片,而且看起来不太好!有谁知道执行此操作的简单方法或我可以查看的上一个和下一个按钮的内容?我想要它,所以每个页面仅限于每页5个帖子或其他内容.

I wanna input previous and next buttons for a forum that i have because after the forum gets to long, it surpasses the background image and doesn't look good! Does anyone know either a simple way to do it or something i can look at for previous and next buttons? I want it so each page is limited to only 5 posts per page or something.

如果有帮助,请在此处输入代码.抱歉,这是一个愚蠢的问题.

Heres the code if it helps at all. I'm sorry if this is a stupid question.

<?php 
$dbc=mysql_connect('host','user','password','database') or die(mysql_error());
mysql_select_db('database',$dbc) or die(mysql_error());
?>

View Posts <br>
<form method="get" action="view_forum.php">
  <label>Select Weather to Filter </label><br />
  <select name="weather">
    <option value="all">all</option>
    <option value="cloudy">Cloudy</option>
    <option value="sunny">Sunny</option>
    <option value="windy">Windy</option>
    <option value="snowy">Snowy</option>
    <option value="mixy">Wintery Mix</option>
    <option value="rainy">Rainy</option>
  </select>
  <input type="submit" value="view" />
</form>

<div id="view">
 <center><img src="images/forum.png" width="589" height="97"></center>
</div>  
  <div id="white">
    <div id="blue">
      <div id="grey">
       <div id="container">
<?php
$weather = mysql_real_escape_string( $_GET["weather"] ); // keep your input clean

if ( $weather == "all" ) {
  $sql = "SELECT * FROM stories ORDER BY id DESC";
} else {
  $sql = "SELECT * FROM stories WHERE weather = '$weather' ORDER BY id DESC";
}

$result = mysql_query( $sql ) or die( mysql_error() );

while ( $row = mysql_fetch_assoc( $result ) ) {

    echo "<div class=\"names\"> {$row['name']}<br /></div>";
    echo "<div class=\"weathers\">{$row['weather']}<br /></div>";
   echo "<div class=\"stories\">{$row['story']}<br /></div>";



        echo "<img src=\"images/line.png\" width='800' height='3'>";

         echo "<br />"; 
}

?>
</div>
</div>
</div>
</div>

推荐答案

很简单.您在请求中保留一个页面变量.如下图所示

It's easy. You keep a page variable in the request. As shown below

if (!isset($_GET['page'])) {
   $page = 1;
} else {
   $page = (int)$_GET['page'];
}

在您的SQL语句中,您将放置如下内容,该内容使用page变量来调整查询限制:

And in you SQL statement, you would put something like this, which uses the page variable to adjust the query limits:

$query = 'SELECT * FROM someTable WHERE 1 LIMIT ' . (($page - 1) * $recordsPerPage) . ' ' . $recordsPerPage;

反正就是这样.现在,在您的上一个和下一个链接中,您需要输入以下内容,以便您可以增加/减少页面变量:

Something like that anyways. Now for your Previous and Next links you put something like this, so that you can increment/decrement the page variable:

<? if ($page > 1) : ?>
   <a href="self.php?page=<?= $page - 1 ?>">Prev</a>
<? endif ?>
<? if ($page != $maxPages) : ?>
   <a href="self.php?page=<?= $page + 1 ?>">Next</a>
<? endif ?>

这篇关于上一个/下一个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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