程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> 無限分類&樹型論壇的實現

無限分類&樹型論壇的實現

編輯:關於PHP編程

數據表參考:
代碼:--------------------------------------------------------------------------------
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);
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved