也就是说你现在的程序给你显示顺序反了??
那把这个
$a="select * from shijian order by date desc limit $offset,$page_size"; //(按时间排序)
改成
$a="select * from shijian order by date limit $offset,$page_size"; //(按时间排序)
那把这个
$a="select * from shijian order by date desc limit $offset,$page_size"; //(按时间排序)
改成
$a="select * from shijian order by date limit $offset,$page_size"; //(按时间排序)
解决方案 »
- 一套系统 支持不同语言 文件下载
- preg_split如何分割$a$b$c$d这样的字符串阿?
- 能不能用 phpstudy2010 去连接mssql???
- onclick 控制两个文本框内容
- php ceil 问题
- php如何读取二进制文件?
- 多语言切换的问题
- 如何取得一个形如链接http://localhost/download?id=5&name=123.dat的下载地址,详细见内
- 老大们:如何获取<input type="file" name="upfile">中的内容,包括完整的路径和文件名!我都快急死了,快来帮帮我啊!我等了好久好久,就
- Thinkphp结构问题
- 别笑我,刚刚学习PHP!
- 用php怎样实现一次前翻后翻多页?
这是完整的程序:<?
$link=mysql_pconnect("localhost","root");
mysql_select_db("mingda",$link);
$query="select * from shijian";
$result=mysql_query($query);
$page_size=3; //(每页显示3个)
if($page<=0)
{$page=1;}
$nums=mysql_num_rows($result);
$page_count=ceil($nums/$page_size);
$offset=($page-1)*$page_size;
$a="select * from shijian order by date limit $offset,$page_size"; //(按时间排序)
$result=mysql_query($a) or die("浏览失败");
$prevpage=$page-1;
$nextpage=$page+1;
echo "目前留言板上共有".$nums."条留言,本页列出了第".$offset."至".$page_count."条\n"."<br>"; //($page_count这个变量怎么不变呀,老是显示3,怎么才能让它跟着变呀)
if ($page<=1)
echo "第一页"." | ";
else
echo "<a href='$PATH_self?page=1'>第一页</a>"." | ";
if ($page<2)
echo "上一页"." | ";
else
echo"<a href='$PATH_self?page=$prevpage'>上一页</a>"." | ";
if ($page+1>$page_count)
echo "下一页"."<br>";
else
echo"<a href='$PATH_self?page=$nextpage'>下一页</a>"."\n<br>";
while ($array=mysql_fetch_array($result))
{
echo $array['delid']."\n";
echo $array['yonghu']."\n";
echo $array['mima']."\n";
echo $array['email']."\n";
echo $array['info']."\n"."<br>";
}
?>可我按你说的试了一下,还是没有改变,其运行结果是:目前留言板上共有8条留言,本页列出了第0至3条 (第一页)目前留言板上共有8条留言,本页列出了第3至3条 (第二页)目前留言板上共有8条留言,本页列出了第6至3条 (第三页,也就是最后一页)
这里的$result是select * from shijian出来的,所以$num是个固定数,跟哪一页没有关系。然后
$page_size=3; //(每页显示3个)
$page_count=ceil($nums/$page_size);$page_size也是固定的数,跟哪一页没关系。那你说$page_count它能不是固定的数?能跟在哪一页有关系吗?
$result=mysql_query($a) or die("浏览失败");
后面加:
$nums=mysql_num_rows($result);
$page_count=ceil($nums/$page_size);
第一页 | 上一页 | 下一页
8 ffff [email protected] 第八个例子
7 dsa [email protected] 第七个例子
6 00000 [email protected] 第六个例子 出完这页以后,就完了,都不能进入下一页了??????
$query="select count(*) from guestbook";
$result=mysql_query($query);$arr=mysql_fetch_array($result);
$num=$arr["count(*)"];
$num2=intval($num/20); //显示20篇每页
for($i=0;$i<=$num2;$i++)
{
echo "<td><a href='list.php?from=".($i*20+1);
echo "'>".($i*20+1)."</a>  </td>";
} <!--文章信息列表标题__>
<tr bgcolor=#ddddaa>
<td width=10% nowrap ><font style="font-size:14">序号</font></td>
<td width=45% nowrap ><font style="font-size:14">标题</font></td>
<td width=20% nowrap ><font style="font-size:14">作者</font></td>
<td width=25% nowrap ><font style="font-size:14">日期</font></td>
//检查调用时是否使用参数from,如果没有,则从第一篇开始
if($from=="")
$from=1;
$to=$from+19;
if($to>$num)
$to=$num; //从数据库中取出本页内容
$query="select id,subject,author,email,date from guestbook
where id>='$from' and id<='$to' order by date";
$result=mysql_query($query);
$num3=mysql_num_rows($result); //如果没有文章
if($num3==0)
{
echo "<tr><td width=100% nowrap ><font color=#ff0000 style='font-size:14'>";
echo "<br><br>本页目前没有文章!</font></tr><br><br>";
} //列表下方提供同样的连接
for($i=0;$i<=$num2;$i++)
{
echo "<td><a href='list.php?from=".($i*20+1);
echo "'>".($i*20+1)."</a>  </td>";
}
//分页控制类
//宇凡 8月15日
?>
<?
class PageControl
{
var $PageAmount; //总页数
var $RecordAmount; //总记录数
var $Page; //当前页码
var $RecordRow_Per_aPage = 5; //每页显示的记录条数,事先预定,不通过程序更改
var $NextPage; //下一页的页码
var $PriorPage; //上一页的页码
var $StartIndex; //相当于每页显示的起始位置的索引
var $UsingIndex; //当前使用的数据的索引
var $arrIDList; //保存ID的数组function PageControl($IDList,$PageNow)
{
if (($PageNow == "") || (round($PageNow) <= 0) )
{
$PageNow=1;
}
$this->arrIDList = $IDList;
$this->Page = $PageNow;
$this->RecordAmount = count($IDList); if ($this->RecordAmount % $this->RecordRow_Per_aPage == 0) {
$this->PageAmount = $this->RecordAmount / $this->RecordRow_Per_aPage;
} else {
$this->PageAmount = ceil($this->RecordAmount / $this->RecordRow_Per_aPage);
}
if ($this->Page > $this->PageAmount)
{
$this->Page = $this->PageAmount;
}
$this->StartIndex = ($this->Page - 1) * $this->RecordRow_Per_aPage;
$this->UsingIndex = $this->StartIndex - 1; //这里减一的目的:得到数据的普遍方法是先Next()再Get数据,比如数据集. if ($this->Page != $this->PageAmount) {
$this->NextPage = $this->Page + 1;
} else {
$this->NextPage = $this->PageAmount;
} if ($this->Page != 1) {
$this->PriorPage = $this->Page - 1;
} else {
$this->PriorPage = 1;
}
}function next_record()
{
$result = false;
if (($this->UsingIndex != $this->RecordAmount - 1) && ($this->UsingIndex - $this->StartIndex < ($RecordRow_Per_aPage - 1))) {
$this->UsingIndex += 1;
$result = true;
} else {
$result = false;
}
return $result;
}function get()
{
$result = $this->arrIDList[$this->UsingIndex];
return $result;
}function show_NowPage()
{
echo "<font color=red>".$this->Page."</font>/".$this->PageAmount;
}function show_FirstLink()
{
echo " <a href=".$PHP_SELF."?p=1>最前页</a> ";
}function show_PriorLink()
{
echo " <a href=".$PHP_SELF."?p=".$this->PriorPage.">上一页</a> ";
}function show_NextLink()
{
echo " <a href=".$PHP_SELF."?p=".$this->NextPage.">下一页</a> ";
}function show_LastLink()
{
echo " <a href=".$PHP_SELF."?p=".$this->PageAmount.">最后页</a> ";
}function show_JumpForm()
{
echo "<FORM METHOD=POST ACTION=".$PHP_SELF.">直接到<INPUT TYPE=text NAME=p size=2 class=input>页 <INPUT TYPE=submit value=GOGOGO class=bottem></FORM>";
}}
?>