-
header('Content-type:text/html; charset=UTF-8');
-
- $conn = mysql_connect('localhost', 'root', '123456') or die('connect to database error!');
- mysql_select_db('xsphp') or die('select database error!');
- mysql_query('SET NAMES utf8');
-
- function showTable($name,$page=1)
- {
-
- $eachPages = 5;
- $url = $_SERVER['PHP_SELF'];
-
- $sql = "SELECT count(*) as total FROM {$name}";
- $result = mysql_query($sql);
- list($rowNums) = mysql_fetch_row($result);
-
- $pageNums = ceil($rowNums / $eachPages);
- $rowFrom = ($page > 1) ? (($page - 1) * $eachPages) : 0;
-
- $sql = "SELECT id,title FROM {$name} LIMIT {$rowFrom},{$eachPages}";
- $result = mysql_query($sql);
-
- echo '
';- echo '
'.$name.'';
-
- //显示标题
- $cols = mysql_num_fields($result);
- echo '
';- for ($i=0; $i echo '
'.mysql_field_name($result,$i).' | ';
- }
- echo '
';
- //显示记录
- while ($row = mysql_fetch_assoc($result)) {
- echo '
';- echo '
'.$row['id'].' | ';
- echo '
'.$row['title'].' | ';
- echo '
';
- }
- //显示Page导航
- echo '
记录共有:'.mysql_num_rows($result) . ' |
';- echo ($page == 1) ? '首页' : '首页';
- echo ' ';
- echo ($page == 1) ? '上一页' : '上一页';
- echo ' ';
- echo ($page == $pageNums) ? '下一页' : '下一页';
- echo ' ';
- echo ($page == $pageNums) ? '尾页' : '尾页';
- echo '
|
';
- }
-
- if (isset($_GET['page']) && $_GET['page'] > 0) {
- $page = $_GET['page'];
- } else {
- $page = 1;
- }
-
- showTable('category',$page);
复制代码
|
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31