PHP 页面跳转的代码

K*K posted @ Mon, 18 Aug 2008 05:42:00 +0800 in 技术 with tags php , 3169 readers
做麦当劳网站的时候写了个页面跳转的代码,足够精简,贴在这里备忘,效果如下图:

页面跳转效果


 1 $connect = mysql_pconnect($host, $username,$password);
 2 mysql_select_db("test");
 3 
 4 $start = $_GET['start'];
 5 $limit = "25";
 6 $query_all = "SELECT id FROM test WHERE disabled=0";
 7 
 8 $result_all = mysql_query($query_all);
 9 $num=mysql_numrows($result_all);
10 
11 // 设置前后页变量
12 $prve=$start-$limit;
13 $next=$start $limit;
14 
15 // 设置向前翻页的跳转
16 if ($prve >= 0) {
17  echo "<a href=test.php?start=$prve _fcksavedurl=test.php?start=$prve _fcksavedurl=test.php?start=$prve _fcksavedurl=test.php?start=$prve>上一页</a>";
18  echo "&nbsp;";
19  echo "\n";
20 }
21 
22 // 显示页码
23 if ($num > $limit) { 
24  $nextstart = 0;
25  $pstart = $start;
26  for ($page = 0; $page < ($num/$limit); $page  ) {
27   $pagedisplay = $page   1;
28   if($page != $pstart / $limit)
29    echo "<a href=\"test.php?start=$nextstart\">";
30   else
31    echo "<font color=\"black\" size=\"3\">";
32    
33   echo "[$pagedisplay]&nbsp;";
34   
35   if($page != $pstart / $limit)
36    echo "</a>";
37   else
38    echo "</font>";
39    
40   echo "\n";
41   
42   if ($page > 0 && ($page % 20) == 0) {
43    break; //退出循环
44   }
45   
46   $nextstart = $nextstart   $limit;
47  }
48 }
49 
50 // 设置向后翻页的跳转
51 if ($next < $num) { 
52  echo "&nbsp;";
53  echo "<a href=test.php?start=$next _fcksavedurl=test.php?start=$next _fcksavedurl=test.php?start=$next _fcksavedurl=test.php?start=$next>下一页</a>";
54  echo "\n";
55 }


Login *


loading captcha image...
(type the code from the image)
or Ctrl+Enter