·您的位置: 首页 » 资源教程 » 编程开发 » PHP » 无限分类&树型论坛的实现

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

类别: PHP教程  评论数:0 总得分:0
数据表参考:

代码:--------------------------------------------------------------------------------
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` )
);
--------------------------------------------------------------------------------


关键的函数

PHP代码:--------------------------------------------------------------------------------
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);
}
}





-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1