データ表参照:
代:------------------------------------------ --------------------------------------
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 .= "`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]['注文'];
$sql = "mf_sort` から `sortid` を選択 ";
$sql .= "where `parentid`='$parentid'";
$x_db->exec($sql);
$n = $x_db->n;
if ($n>0)
{
$lastid = $parentid;
get_lastid($lastid);
$sql = "mf_sort` から `orders` を選択 ";
$sql .= "where `sortid`='$lastid'";
$x_db->exec($sql);
$data = $x_db->get_data();
$orders = $data[0] [0];
$sql = "`mf_sort` を更新 ";
$sql .= "set `orders`=`orders`+1 ";
$sql .= "where `orders`>$orders と `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 および `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);
}
}