Home > Article > Backend Development > 总是报错 !
// 确定当前页数 $p 参数$p = $_GET['p']?$_GET['p']:1;// 数据指针$offset = ($p-1)*$pagesize;$query_sql = "SELECT * FROM guestbook ORDER BY id DESC LIMIT $offset , $pagesize";$result = mysql_query($query_sql);// 如果出现错误并退出if(!$result) exit('查询数据错误:'.mysql_error());// 循环输出while($gb_array = mysql_fetch_array($result)){?><div class="guestbook-list"><p class="guestbook-head"><img src="images/<?=$gb_array['face']? alt="总是报错 !" >.gif" /><span class="bold"><?=$gb_array['nickname']?></span> <span class="guestbook-time">[<?=date("Y-m-d H:i", $gb_array['createtime'])?>]</span></p><p class="guestbook-content"><?=nl2br($gb_array['content'])?></p><?php // 回复 if(!empty($gb_array['replytime'])) {?><p class="guestbook-head">管理员回复: <span class="guestbook-time">[<?=date("Y-m-d H:i", $gb_array['replytime'])?>]</span></p><p class="guestbook-content"><?=nl2br($gb_array['reply'])?></p><?php } // 回复结束?></div><?php} //while循环结束?><div class="guestbook-list guestbook-page"><p><?php//计算留言页数$count_result = mysql_query("SELECT count(*) FROM guestbook");$count_array = mysql_fetch_array($count_result);$pagenum = ceil($count_array['count(*)']/$pagesize);echo '共 ',$count_array['count(*)'],' 条留言';if ($pagenum > 1) { for($i=1;$i<=$pagenum;$i++) { if($i==$p) { echo ' [',$i,']'; } else { echo ' <a href="index.php?p=',$i,'">'.$i.'</a>'; } }}?></p></div></div><!--留言列表结束-->
<?php/******************************数据库连接*****************************/$conn = @mysql_connect("localhost","","");if (!$conn){ die("连接数据库失败:" . mysql_error());}mysql_select_db("guestbook", $conn);//字符转换,读库mysql_query("set character set 'gbk'");//写库mysql_query("set names 'gbk'");?>
CREATE TABLE `guestbook` ( `id` mediumint(8) unsigned NOT NULL auto_increment, `nickname` char(16) NOT NULL, `email` varchar(60) default NULL, `face` tinyint(2) unsigned NOT NULL default '1', `content` text NOT NULL, `createtime` int(10) unsigned NOT NULL default '0', `clientip` char(15) NOT NULL, `reply` text, `replytime` int(10) unsigned default NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
$_GET['p'] 是传入的变量,第一次执行就不会有,所以会报错
$p = isset($_GET['p']) ? $_GET['p'] : 1;