新版如何落伍 | 站长知道 | 落伍预告页 | 站长运营 | 站长赚钱 | 站长代码 | 站长任务 | 站长招聘 | 落伍T恤 | 积分说明 | 帐号保护和激活
91ivr火爆点歌联盟 效果最强体育产品注册, 每个2元。提升流量, 赚钱, 上开心搜揽众浙江电信15M,广东电信10M,549起
黑马联盟2008年新品新举措!中客: 空间产品随时可无条件退款!0168.com 24小时现机租用百独托管1000起,电信租用499
乐乐联盟—最好的图铃联盟英拓酷睿机器+1元,升级为2G内存九天智能建网站 2008投资好项目盟者Q币 独家奥运抢票 比点歌更强
DNSPod智能DNS,我们一直在免费莆阳:E4500/2G年付6999元送产权雅唐网络酷睿服务器499元/月256M内存VPS主机138/月
 13 12
发新话题
打印

无限分类&树型论坛的实现

无限分类&树型论坛的实现

数据表参考
复制内容到剪贴板
代码:
CREATE TABLE `mf_sort` (
`sortid` SMALLINT( 3 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
`main` TINYINT( 2 ) UNSIGNED NOT NULL ,
`parentid` SMALLINT( 3 ) UNSIGNED NOT NULL ,
`layer` SMALLINT( 3 ) UNSIGNED NOT NULL ,
`orders` TINYINT( 2 ) UNSIGNED NOT NULL ,
`sort` VARCHAR( 100 ) NOT NULL ,
PRIMARY KEY ( `sortid` ) ,
INDEX ( `main` , `parentid` , `layer` , `orders` )
);

#sortid 类别编号
#main  根分类
#parentid 父ID
#layer 分类等级
#orders 排列顺序
主要函数,用于添加分类时用,根分类除外:
复制内容到剪贴板
代码:
function get_main_layer_orders($parentid)
{
    global $x_db;
    $sql  = "select `main`, `layer`, `orders` ";
    $sql .= "from `mf_sort` ";
    $sql .= "where `postid`='$parentid'";
    $x_db->exec($sql);
    $data   = $x_db->get_data();
    $layer  = $data[0]['layer']+1;
    $main   = $data[0]['main'];
    $orders = $data[0]['orders'];

    $sql  = "select `sortid` from `mf_sort` ";
    $sql .= "where `parentid`='$parentid'";
    $x_db->exec($sql);
    $n = $x_db->n;
    if ($n>0)
    {
        $lastid = $parentid;
        get_lastid($lastid);
        $sql    = "select `orders` from `mf_sort` ";
        $sql   .= "where `sortid`='$lastid'";
        $x_db->exec($sql);
        $data   = $x_db->get_data();
        $orders = $data[0][0];
        $sql    = "update `mf_sort` ";
        $sql   .= "set `orders`=`orders`+1 ";
        $sql   .= "where `orders`>$orders and `main`='$main'";
        $x_db->exec($sql);
        $orders = $orders + 1;
        return array($main, $layer, $orders);
    }
    else
    {
        $sql    = "update `mf_sort` ";
        $sql   .= "set `orders`=`orders`+1 ";
        $sql   .= "where `orders`>$orders and `main`='$main'";
        $x_db->exec($sql);
        return array($main, $layer, $orders+1);
    }
}

//取得最后一个有效sortid
function get_lastid(&$parentid)
{
    global $x_db;
    $pre  = $parentid;
    $sql  = "select max(`sortid`) as `id` ";
    $sql .= "from `mf_sort` ";
    $sql .= "where `parentid` = '$parentid'";
    $x_db->exec($sql);
    $data = $x_db->get_data();
    $id   = $data[0]['id'];
    if (empty($id))
    {
        $parentid = $pre;
    }
    else
    {
        $parentid = $id;
        get_lastid($parentid);
    }
}
演示:http://forum.2fs.cn/forumdisplay.php?forumid=1&tree=1
不接落伍任何人商业单子
以后也不在落伍找人买东西之类的了,骗子他妈的一大堆
利用orders控制顺序,添加分类时用递归,查询时直接输出不用递归。
不接落伍任何人商业单子
以后也不在落伍找人买东西之类的了,骗子他妈的一大堆

TOP

不懂,帮忙T一下技术帖,落伍需要
想出去旅游?专业户外用品专卖---专业人士提供咨询 shop35724197.taobao.com

TOP

$x_db 所用到的数据库类
复制内容到剪贴板
代码:
/*****
// +-------------------------------------------------
// | Id: vbf_db.php                                 
// +-------------------------------------------------
// | Copyright (c)  
// | Author:Arvan
// +-------------------------------------------------
// | Create Date: 2003-6-23
// | Modify Date:
// | Note:
// |        数据库操作的类
// |
// |
// +-------------------------------------------------
*****/

class TDb{
        var $host;
        var $user;
        var $password;
        var $database;

        var $n;
        var $result="";
        var $conn="";

        var $debug = true;
        var $errMsg = "";

        function TDb($host,$user,$password,$database){
                $this->host=$host;
                $this->user=$user;
                $this->password=$password;
                $this->conn=@mysql_connect($host,$user,$password) or die("<br><br><b>Err:</b>SQL busy,please try again later!");
               
                $this->set_db($database);

                $this->errMsg ="";
                $this->n = 0;
        }
        //end of func tdb

        function exec($sql, $db_name = ''){
                if (($db_name != '') && ($db_name != $this->database)){
                        $old_db = $this->database;
                        $this->set_db($db_name);
                }
                $this->n = 0;
                $this->result=@mysql_query($sql,$this->conn);
                if (mysql_error() != ""){
                        $this->errMsg = mysql_error();
                        if ($this->debug){
                                echo "<br><br><b>Err:</b>Fail to execute this SQL query:$sql<br><br>$this->errMsg";
                        }else{
                                echo "<br><br><br><b>Err:</b>Please check the query is normal and make sure that It's allowed!";
                        }
                        exit;
                }
                $this->n = @mysql_affected_rows();
                if($old_db != ''){
                        $this->set_db($old_db);
                }
                return true;
        }

        function get_data(){
                if($this->result==""){
                        echo "<br><br><b>Err:</b>There is no result please run method exec(\$sql) first";
                        exit;
                }
                $count=0;
                while($row=mysql_fetch_array($this->result)){
                        $data[$count]=$row;
                        $count++;
                }
                mysql_free_result($this->result);
                return $data;
        }
        //end of func get_data


        function get_ins_id(){
                return mysql_insert_id();
        }

        function free(){
                mysql_close($this->conn);
        }

        function set_db($db_name){
                if($db_name != $this->database){//select new table while they are different
                        @mysql_select_db($db_name) or die("<br><b>Err:</b>Fail to select $db_name table, make sure it's allowed to do this!");
                        $this->database=$db_name;
                }
                return true;
        }

        function get_cur_db(){
                return $this->database;
        }
}
//End of class db
不接落伍任何人商业单子
以后也不在落伍找人买东西之类的了,骗子他妈的一大堆

TOP

不用递归就好啊
全部整理了提供下载啊,呵呵,好东西,就是太简单了些
第二排名 中文排名
友情链接交换平台 高PR等你来链接!

TOP

数据库结构是怎么样的
因为我和你的存在,落伍将更加精彩!  
因为落伍的精彩,Internet将更加灿烂!   

TOP

无限分类,我以前就搞过,就是感觉不是很满意,分的太多的话,我无法确定它的执行效率怎么样!!不过就3,4及来讲是没有任何问题的,
老是陶醉在盲目跟无知中!真是悲哀啊!

TOP

引用:
Originally posted by 西瓜 at 2003-9-23 09:26 PM:
数据库结构是怎么样的
不是给出了吗?
不接落伍任何人商业单子
以后也不在落伍找人买东西之类的了,骗子他妈的一大堆

TOP

引用:
Originally posted by 风月无边 at 2003-9-23 09:24 PM:
不用递归就好啊
全部整理了提供下载啊,呵呵,好东西,就是太简单了些
使用递归的地方是添加新类的时候用的,如果是树型 论坛的话,就是发新贴的时候用到。其他时候都是查询,不用递归.
不接落伍任何人商业单子
以后也不在落伍找人买东西之类的了,骗子他妈的一大堆

TOP

我记得simpleboard就有Arvan论坛类似的功能

TOP

 13 12
发新话题