仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2324|回复: 20
打印 上一主题 下一主题

[学习教程] PHP网站制作之非递归法完成服装论坛树型布局及分页!!(...

[复制链接]
蒙在股里 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-4 00:23:54 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
终于学会把表单的数据插入数据库,然后显示出来了,应该说一个程序的雏形已经诞生了。递归|分页|树型布局   现将自己的理论了局show给人人,缺乏的地方就是分页的办法不太好,不克不及显示详细的页数,可其实又没有其它更好的处理举措,只好先如斯了,假如哪位有相似本服装论坛的分页办法,表赐教一二,二泉不堪感谢!详细可会见我的团体小网站:http://web.nyist.net/~wbgwrq,不空话了,入手下手吧......

//表的布局以下:
//creat.sql
//复杂申明:RootId 论题序数;Layer:帖子条理,缩进的根据;Orders:帖子的按次
CREATE TABLE over_post (
  id int(11) NOT NULL auto_increment,
  title varchar(80) NOT NULL default '',
  content text,
  postat datetime NOT NULL default '0000-00-00 00:00:00',
  readed int(11) NOT NULL default '0',
  size int(11) NOT NULL default '0',
  rootid int(11) NOT NULL default '0',
  orders int(4) NOT NULL default '0',
  layer int(4) NOT NULL default '0',
  PRIMARY KEY  (id)
) TYPE=MyISAM;
//creat.sql End

//宣布根帖,即RootId,Layer,Orders为0的帖子
//said.php
//begin
<form method="post" action="post.php">
  <table width="81%" border="0" cellspacing="1" cellpadding="0" align="center">
    <tr bgcolor="#66CCCC">
      <td height="35" width="23%">
        <div align="right">你的设法:
        </div>
      </td>
      <td height="35" width="77%">
        <input type="text" name="title" size="50" class="eq">
      </td>
    </tr>
    <tr bgcolor="#66CCCC">
      <td height="39" width="23%">
        <div align="right">你的内容:
        </div>
      </td>
      <td height="39" width="77%">
        <textarea name="content" cols="50" rows="10" class="eq"></textarea>
      </td>
    </tr>
    <tr bgcolor="#66CCCC">
      <td colspan="2" height="24">
      </td>
    </tr>
    <tr bgcolor="#66CCCC">
      <td colspan="2" height="28">
        <div align="center">
          <input type="submit" name="said" value="先说这些">
          <input type="reset" name="Submit2" value="从头再来">
        </div>
      </td>
    </tr>
  </table>
  </form>
//said.php End


//帖子内容,且在本页停止跟帖
//content.php
//Begin
<?php

$result=mysql_query("select

over_post.title,over_post.content,over_post.postat,over_post.readed,over_post.rootid,over_post.la

yer,over_post.orders from over_post where over_post.id=$id");
$readed=mysql_result($result,0,"readed");
$title=mysql_result($result,0,"title");
$content=mysql_result($result,0,"content");
$date=mysql_result($result,0,"postat");
$rootid=mysql_result($result,0,"rootid");
$orders=mysql_result($result,0,"orders");
$layer=mysql_result($result,0,"layer");
?>
<table width="90%" cellspacing="1" bgcolor="red" align="center">
  <tr bgcolor="#FFFFFF">
   <td width="12%">宣布人:</td>
  </tr>
  <tr bgcolor="#FFFFFF">
     <td width="12%">主 题:</td>
     <td colspan="5">《<?php echo $title; ?>》  <font color="666666"><i>【

Readed:<?echo"$readed";?>】  <?echo"$date";?></i></font></td>
              </tr>
   <tr bgcolor="#FFFFFF">
     <td width="12%">内 容:</td>
     <td colspan="5"><?php echo $content; ?></td>
   </tr>
</table>
<br>
<center>
  服装论坛宣布跟帖
  <form method="post" action="post.php">
    <table width="78%" cellspacing="0" align="center" cellpadding="0" border="0">
      <tr bgcolor="#FFFFFF">
        <td height="24" width="12%">
          <div align="right">标题:</div>
        </td>
        <td height="24" width="88%">
          <input type="text" name="title" class="eq" size="50">
        </td>
      </tr>
      <tr bgcolor="#FFFFFF">
        <td height="63" width="12%">
          <div align="right">内容:</div>
        </td>
        <td height="63" width="88%">
          <textarea name="content" class="eq" cols="50" rows="10"></textarea>
        </td>
      </tr>
      <tr bgcolor="#FFFFFF">
        <td height="57" colspan="2">
        </td>
      </tr>
      <tr bgcolor="#FFFFFF">
        <td height="20" colspan="2">
          <div align="center">
          <input type="submit" name="reply" value="跟帖" class=in>
          <input type="reset" value="重写" class=in name="reset">
          <input type="hidden" name="rootid" value="<?echo $rootid;?>">
          <input type="hidden" name="orders" value="<?echo$orders;?>">
          <input type="hidden" name="layer" value="<?echo$layer;?>">
          </div>
        </td>
      </tr>
    </table>
//content.php End

//更新数据库
//post.php
//Begin

<?
$content=nl2br(htmlspecialchars($content));
$title=htmlspecialchars($title);        //决不答应在题目上利用html
$date=date("Y-m-d H:i:s");
$length=strlen($content);

if(isset($said))    //宣布新帖子
{
$query="insert into over_post

values(null,'$title','$content',$user_id,'$date',0,$length,$img,'','','')";
$result=mysql_query($query) or die(mysql_error());
$r=mysql_query("select max(id) from over_post");
$rootid = mysql_result($r,0)+0;
mysql_query("update over_post set rootid=$rootid where ID=$rootid")or die(mysql_error());
}

if(isset($reply)):    //宣布跟帖

mysql_query("update over_post set orders=orders+1 where rootid=$rootid and orders>$orders")or

die(mysql_error());

$layer=$layer+1;
$orders=$orders+1;
$query="insert into over_post

values(null,'$title','$content',$user_id,'$date',0,$length,$img,$rootid,$orders,$layer)";

$result=mysql_query($query) or die(mysql_error());

endif;
     if($result) {
    include"list.php";
}
?>
//post.php End

//重头戏,显示一切帖子,并完成分页
//list.php
//Begin

<?php
//找到最新论题的rootid
$query = "select max(rootid) as maxid1, min(rootid) as minid1 from over_post";
$result = mysql_query($query);
$maxid1 = mysql_result($result, 0, "maxid1");
$startid1 = mysql_result($result, 0, "minid1");
if(!($maxid1>0)) $maxid1=0;
if(!($startid1>0)) $startid1=0;
$totalid1 = $maxid1; //这是真实的最大的rootid值, $maxid1要依据$nextmaxid1变的
if($nextmaxid1>0) $maxid1=$nextmaxid1; //翻页

//盘算最小rootid:注重上面的desc,与limit联合,包管拔取纪录的局限.
//假如利用asc, 在mysql_result中检索第0个,将大大毛病!
$itemsperpage=30;
$query="select distinct rootid from over_post where rootid<=$maxid1 order by rootid desc limit

$itemsperpage";
$r=mysql_query($query);
$n=mysql_num_rows($r);
if($n>0) {
  $minid1=mysql_result($r,$n-1);
$query="select * from over_post where rootid<=$maxid1 and rootid>=$minid1 order by rootid

desc,orders";
$result=mysql_query($query);
$num=mysql_num_rows($result);

}
else {
  $minid1=0;
  $maxid1=0;
  echo "<p><center><font color='#ff0000'>没有更多的讲话内容</font></center>";
}

$query="select distinct rootid from over_post where rootid>$maxid1 order by rootid limit

$itemsperpage";
$r=mysql_query($query);
$n=mysql_num_rows($r);
if($n>0) $up=mysql_result($r,$n-1);
else $up=$totalid1;

$query="select distinct rootid from over_post where rootid<$minid1 order by rootid desc limit

$itemsperpage";
$r=mysql_query($query);
$n=mysql_num_rows($r);
if($n>0) $down=mysql_result($r,0);
else $down=$maxid1;
?>
<div align=center>
<br>
  <table width="90%" border="0" cellspacing="1" cellpadding="0" align="center">
    <tr bgcolor="2880AC">
      <td height="20" align="center"><font color="#FFFFFF"><a

href="javascript:window.location.reload()" class=a1>刷新</a>
        <a href="list.php" class=a1>首页</a> <a href="list.php?nextmaxid1=<?echo$up;?>" class=a1>

上页</a>
        <a href="list.php?nextmaxid1=<?echo$down;?>" class=a1>下页</a>  <?echo" 现存论题

:$startid1-$totalid1 ";?>
        </font></td>
    </tr>
    <tr>
      <td  height="40" bgcolor="#E0F0F8" cellspacing="1">
<?php
echo"<ul>";
while ($array=mysql_fetch_array($result)){
        $id=$array["id"];
        $title=$array["title"];
        $content=$array["content"];
        $postat=$array["postat"];
        $readed=$array["readed"];
        $size=$array["size"];
            if($size==0) $size="无内容";
                else $size.=" Bytes";
        $rootid=$array["rootid"];
        $orders=$array["orders"];
        $layer=$array["layer"];
            
        $ul="";        //入手下手树型布局
        $_ul="";
    for($j=0;$j<$layer;$j++){
            $ul=$ul."<ul>";
            $_ul=$_ul."</ul>";   
            }
echo $ul."<li>"."<a href=\"content.php?id=$id\" class=big>$title</a><font color=006699>($size) 【

".作者."】 $postat <被读:$readed> </font><br>".$_ul;
flush();
                //树型布局停止
}
?><br></td>
    </tr>
    <tr bgcolor="2880AC">
      <td height="20" align="center"><font color="#FFFFFF"><a

href="javascript:window.location.reload()" class=a1>刷新</a>
        <a href="list.php" class=a1>首页</a> <a href="list.php?nextmaxid1=<?echo$up;?>" class=a1>

上页</a>
        <a href="list.php?nextmaxid1=<?echo$down;?>" class=a1>下页</a>  <?echo" 现存论题

:$startid1-$totalid1 ";?>
        </font></td>
    </tr>
  </table>
</div>

//list.php End  你的确对PHP有兴趣,那么选择教材也是很重要的。
蒙在股里 该用户已被删除
沙发
 楼主| 发表于 2015-7-15 09:30:48 | 显示全部楼层
找到的的资料很多都是在论坛里的,需要注册,所以我一般没到一个论坛都注册一个id,所有的id都注册成一样的,这样下次再进来的时候就不用重复注册啦。当然有些论坛的某些资料是需要的付费的。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-13 05:01

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表