php-分页实例
1
<?
2
$query_string='cateid='.$cateid;
3
$sql="select id,title,author,nowtime,view_times from companynews where cate=$cateid and subcate=3 order by id desc";
4
$dblink->query($sql);
5
$num=$dblink->num_rows();
6
$rec_num=$num;
7
$rec_per_page=30;
8
if(isset($_GET["page"]) && floor($_GET["page"])>0)
9
{
10
$page=floor(trim($_GET["page"]));
11
}
12
else
13
{
14
$page=1;
15
}
16
if(ceil($num/$rec_per_page)>=$page)
17
{
18
$start=$rec_per_page*($page-1);
19
}
20
else
21
{
22
$page=1;
23
$start=0;
24
}
25
if($num>$page*$rec_per_page)
26
{
27
$this_page_count=$rec_per_page;
28
}
29
else
30
{
31
$this_page_count=$num-($page-1)*$rec_per_page;
32
}
33
if($num==0)
34
{
35
?>
36
<tr>
37
<td colspan="5" height="50"><b><font color="#FF0000">对不起,数据库中暂时没有公司动态信息!</font></b></td>
38
</tr>
39
40
<?}
41
else
42
{?>
43
<tr bgcolor="#DDDDDD">
44
<td height="30" align="center" width="40" nowrap>序号</td>
45
<td >主题</td>
46
<td width="60">来源</td>
47
<td width="80">发布时间</td>
48
<td align="center" width="0"> </td>
49
</tr>
50
<?
51
for($i=0;$i<$num;$i++)
52
{
53
$article_data=$dblink->next_record();
54
if($i<$start || $i>=$start+$this_page_count)
55
{
56
continue;
57
}
58![]()
59
?>
60
<tr bgcolor="#EFEFEF">
61
<td align="center" height="20" bgcolor="#EFEFEF"><?echo $i+1;?></td>
62
<td nowrap ><a href="article.php?id=<?echo trim($article_data["id"]);?>" title="<?echo trim($article_data["title"]);?>"><?echo csubstr(trim($article_data["title"]),0,70);?></a></td>
63
<td ><?echo trim($article_data["author"]);?></td>
64
<td nowrap><?echo trim($article_data["nowtime"]);?></td>
65
<td align="center"> </td>
66
</tr>
67
<?
68
}
69
}?>
70
<tr>
71
<td colspan="5" height="80"><b>
72
<?
73
echo "总共记录数目:<font color='#FF0000'><b>".$rec_num."</b></font>。
74
每页有<font color='#FF0000'><b>$rec_per_page</b></font>条记录。
75
共有<font color='#FF0000'><b>".ceil($rec_num/$rec_per_page)."</b></font>页。
76
当前是第<font color='#FF0000'><b>$page</b></font>页。<br><br>";
77
if($page==1)
78
{
79
echo "<font color='#CCCCCC'>第一页 上一页 </font>";
80
}
81
else
82
{
83
echo "<a href=\"$File_Name?page=1&$query_string\">第一页</a> "."<a href=\"$File_Name?page=".($page-1)."&$query_string\">上一页</a> ";
84
}
85
if($this_page_count!=$rec_per_page || $rec_num==$page*$rec_per_page)
86
{
87
echo "<font color='#CCCCCC'>下一页 最后一页</font>";
88
}
89
else
90
{
91
echo "<a href=\"$File_Name?page=".($page+1)."&$query_string\">下一页</a> "."<a href=\"$File_Name?page=".ceil($rec_num/$rec_per_page)."&$query_string\">最后一页</a>";
92
}
93
if(ceil($rec_num/$rec_per_page)>1)
94
{
95
echo "转到<input type='input' name='input_page' class='input' style='width:30' onKeyDown=\"if(window.event.keyCode==13){location.href='$File_Name?page='+input_page.value+'&$query_string'}\">页 <input type='button' name='go' value='GO' class='input' onClick=\"Javascript:location.href='$File_Name?page='+input_page.value+'&$query_string'\">";
96
}
97
?> </b></td>
<?2
$query_string='cateid='.$cateid;3
$sql="select id,title,author,nowtime,view_times from companynews where cate=$cateid and subcate=3 order by id desc";4
$dblink->query($sql);5
$num=$dblink->num_rows();6
$rec_num=$num;7
$rec_per_page=30;8
if(isset($_GET["page"]) && floor($_GET["page"])>0)9
{10
$page=floor(trim($_GET["page"]));11
}12
else13
{14
$page=1;15
}16
if(ceil($num/$rec_per_page)>=$page)17
{18
$start=$rec_per_page*($page-1);19
}20
else21
{22
$page=1;23
$start=0;24
}25
if($num>$page*$rec_per_page)26
{27
$this_page_count=$rec_per_page;28
}29
else30
{31
$this_page_count=$num-($page-1)*$rec_per_page;32
}33
if($num==0)34
{35
?> 36
<tr> 37
<td colspan="5" height="50"><b><font color="#FF0000">对不起,数据库中暂时没有公司动态信息!</font></b></td>38
</tr>39
40
<?}41
else42
{?> 43
<tr bgcolor="#DDDDDD"> 44
<td height="30" align="center" width="40" nowrap>序号</td>45
<td >主题</td>46
<td width="60">来源</td>47
<td width="80">发布时间</td>48
<td align="center" width="0"> </td>49
</tr>50
<?51
for($i=0;$i<$num;$i++)52
{53
$article_data=$dblink->next_record();54
if($i<$start || $i>=$start+$this_page_count)55
{56
continue;57
}58

59
?> 60
<tr bgcolor="#EFEFEF"> 61
<td align="center" height="20" bgcolor="#EFEFEF"><?echo $i+1;?></td>62
<td nowrap ><a href="article.php?id=<?echo trim($article_data["id"]);?>" title="<?echo trim($article_data["title"]);?>"><?echo csubstr(trim($article_data["title"]),0,70);?></a></td>63
<td ><?echo trim($article_data["author"]);?></td>64
<td nowrap><?echo trim($article_data["nowtime"]);?></td>65
<td align="center"> </td>66
</tr>67
<?68
}69
}?> 70
<tr> 71
<td colspan="5" height="80"><b>72
<?73
echo "总共记录数目:<font color='#FF0000'><b>".$rec_num."</b></font>。74
每页有<font color='#FF0000'><b>$rec_per_page</b></font>条记录。75
共有<font color='#FF0000'><b>".ceil($rec_num/$rec_per_page)."</b></font>页。76
当前是第<font color='#FF0000'><b>$page</b></font>页。<br><br>";77
if($page==1)78
{79
echo "<font color='#CCCCCC'>第一页 上一页 </font>";80
}81
else82
{83
echo "<a href=\"$File_Name?page=1&$query_string\">第一页</a> "."<a href=\"$File_Name?page=".($page-1)."&$query_string\">上一页</a> ";84
}85
if($this_page_count!=$rec_per_page || $rec_num==$page*$rec_per_page)86
{87
echo "<font color='#CCCCCC'>下一页 最后一页</font>";88
}89
else90
{91
echo "<a href=\"$File_Name?page=".($page+1)."&$query_string\">下一页</a> "."<a href=\"$File_Name?page=".ceil($rec_num/$rec_per_page)."&$query_string\">最后一页</a>";92
}93
if(ceil($rec_num/$rec_per_page)>1)94
{95
echo "转到<input type='input' name='input_page' class='input' style='width:30' onKeyDown=\"if(window.event.keyCode==13){location.href='$File_Name?page='+input_page.value+'&$query_string'}\">页 <input type='button' name='go' value='GO' class='input' onClick=\"Javascript:location.href='$File_Name?page='+input_page.value+'&$query_string'\">";96
}97
?> </b></td>

浙公网安备 33010602011771号