$query=mysql_query("select * from tb_xxgk where id='{$_GET['id']}'",$conn); while($myrow_1=mysql_fetch_array($query)) $info=$row[content]; //打印文章内容 }else{ //如果没有选择哪篇文章就打印第一篇 $query=mysql_query("select * from tb_xxgk order by id asc limit 1",$conn); $row=mysql_fetch_array($query); $info=$row[content];
或者你用ajax读取内容也行,
<table width="670" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="670" height="50"><div align="center"><?php include("conn/conn.php");?>
<?phpif($_GET['id']){
$id=$_GET['id'];
$query=mysql_query("select * from tb_xxgk where id='$id'",$conn);
$row=mysql_fetch_array($query);
echo "$row[title]"; //打印文章内容
}else{
echo "匿名";
}
?></div></td>
</tr>
<tr>
<td><table width="400" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="50">作者:</td>
<td width="80"><?php include("conn/conn.php");?>
<?phpif($_GET['id']){
$id=$_GET['id'];
$query=mysql_query("select * from tb_xxgk where id='$id'",$conn);
$row=mysql_fetch_array($query);
echo "$row[author]"; //打印文章内容
}else{
echo "匿名";
}
?>
</td>
<td width="100">上传时间:</td>
<td width="158"><?php include("conn/conn.php");?>
<?phpif($_GET['id']){
$id=$_GET['id'];
$query=mysql_query("select * from tb_xxgk where id='$id'",$conn);
$row=mysql_fetch_array($query);
echo "$row[time]"; //打印文章内容
}else{
echo "匿名";
}
?></td>
</tr>
</table></td>
</tr>
<tr>
<td><?php
function cut_str($string,$start = 0, $sublen , $code = 'gb2312'){
if($code == 'UTF-8'){
$pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/";
preg_match_all($pa, $string, $t_string);
if(count($t_string[0]) - $start > $sublen) return join('', array_slice($t_string[0], $start, $sublen));
return join('', array_slice($t_string[0], $start, $sublen));
}
else{
$start = $start*2;
$sublen = $sublen*2;
$strlen = strlen($string);
$tmpstr = '';
for($i=0; $i< $strlen; $i++){
if($i>=$start && $i< ($start+$sublen)){
if(ord(substr($string, $i, 1))>129){
$tmpstr.= substr($string, $i, 2);
}
else{
$tmpstr.= substr($string, $i, 1);
}
}
if(ord(substr($string, $i, 1))>129) $i++;
}
if(strlen($tmpstr)< $strlen){
}
return $tmpstr;
}
}
if(isset($_GET["now_page"])){
$now_page = $_GET["now_page"];
$now_page = intval($now_page);
}
if($now_page==""||$now_page<1){
$now_page = 1;
}if($_GET['id']){
$query=mysql_query("select * from tb_xxgk where id='{$_GET['id']}'",$conn);
while($myrow_1=mysql_fetch_array($query))
$info=$row[content]; //打印文章内容
}else{ //如果没有选择哪篇文章就打印第一篇
$query=mysql_query("select * from tb_xxgk order by id asc limit 1",$conn);
$row=mysql_fetch_array($query);
$info=$row[content];
}
//$info = "adsfaefadfeafadsfefasafi239asjf93asdiofjioaksdfj90asdjiojeioiojcaEIAZNIAEFNIASDFIEFNIASDFNAWEOFI912JKISDFEIANFIEFANIDFEIADIFENIADIFEsdfffffffffffasdfefef";//信息内容
$each_page_save_words_num = 500;//每$each_page_save_words_num个字换页
$count_words = mb_strlen($info,'gb2312');//字符统计
$count_page = ceil($count_words/$each_page_save_words_num);//总页码
//开始字数:
$start_words = ($now_page-1)*$each_page_save_words_num;$out = cut_str($info,$start_words,$each_page_save_words_num ,'gb2312');
//输出信息:完毕
echo $out.'<br/>';//分页处理
$show_page = 5;//显示5个页码
$url = "gk.php";//当前的文件名if($now_page>1){
$last_page = $now_page -1;
}
else{
$last_page = 1;
}
//下一页
if($now_page<$count_page){
$next_page = $now_page +1;
}
else{
$next_page = $count_page;
}
if($count_page<=$show_page){
$start = 1;
$end = $count_page;
}
else{
if($now_page<=($show_page+1)/2){
$start = 1;
$end = $show_page;
}
else if($now_page>($count_page-($show_page+1)/2)){
$start = $count_page - $show_page+1;
$end = $count_page;
}
else{
$start = $now_page - ($show_page-1)/2;
$end = $now_page + ($show_page-1)/2;
}
}
$page = "<a href='".$url."?now_page=1'>首页</a> ";
$page .= "<a href='".$url."?now_page=".$last_page."'>上一页</a> ";
//echo $start.'<br/>';
//echo $end.'<br/>';
for($i=$start;$i<=$end;$i++){
if($i==$now_page){
$page .= "<a style=\"color:#ff0000;\" href='".$url."?now_page=".$i."'>".$i."</a> ";//当前页颜色变红
}
else{
$page .= "<a href='".$url."?now_page=".$i."'>".$i."</a> ";
}
}
$page .= "<a href='".$url."?now_page=".$next_page."'>下一页</a> ";
$page .= "<a href='".$url."?now_page=1".$count_page."'>尾页</a> ";
echo $page;
?> </td>
</tr>
</table>
恩,是的。
而且你要在获取参数的地方多执行一步:
放在查询结果后面
if(!$title){
$title = $_GET['title'];
}
if(!$content){
$content = $_GET['content'];
}
<?phpif($_GET['id']){
$id=$_GET['id'];
$query=mysql_query("select * from tb_xxgk where id='$id'",$conn);
$row=mysql_fetch_array($query);
echo "$row[title]"; //打印文章内容
}else{
echo "无";
}
if(!$title){
$title = $_GET['title'];
}?>但是也不对诶,和以前一样,一点击下一页就只显示 无
$id
$query
$row
$row['title']
看值
那你就不需要传值了,既然点击下一页都要重新查询。
那就把content段从数据库中取出来,根据分页取mb_substr();然后显示吧。例如,page = 1是
$nowContent = mb_substr($content,0,1000);
echo $nowContent;
echo $title;page = 2时显示
$nowContent = mb_substr($content,1000,1000);
echo $nowContent;
echo $title;
......