|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
你的确对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);
}
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);
}
}
讲了这么多,无非是想说:学习PHP不仅要掌握方法,更多的是付出汗水,我不希望看到中途放弃的人,相信自己,相信自己的选择,更要相信自己的能力,如果自己想放弃,暴力一点的话,就自己抽自己一个嘴巴。 |
|