欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【PHP实例:PHP无限极分类】,下面是详细的分享!
PHP实例:PHP无限极分类
php无限极分类CODE=PHP]
至于添加删除之类的功能我就不多写了!仔细看看就知道这么用了.
难的是显示方面
希望高手扩展一下!
QUOTE:
这是类
<?php
class catalog{
var config;
var catalog_dbname;
var links;
private function connect(){
this->links=mysql_connect(this->config['host'],this->config['user'],this->config['pass']) or die("错误: 第".__LINE__."行<br>".mysql_error());
mysql_select_db(this->config['dbname'],this->links);
mysql_query("SET NAMES gb2312");
}
function catalog_show(uid=0){
this->connect();
sql="SELECT * FROM ".this->catalog_dbname. "
WHERE catalog_uid=". uid ."
ORDER BY catalog_id ";
result=mysql_query(sql,this->links) or die("错误: 第".__LINE__."行<br>".mysql_error());
if(mysql_num_rows(result) > 0){
while (row=mysql_fetch_assoc(result)){
if(this->sun_catalog(row['catalog_id'])){//判断有没有子分类
cata_img="<img id='img".row['catalog_id']."' src='http://www.chinaz.com/program/2008/1118/./img/last_node.jpg' ōnclick='click_catalog(".row['catalog_id'].")'/>";
}else{
cata_img="<img src='http://www.chinaz.com/program/2008/1118/./img/sp.jpg'/>";
}
path=explode(":",row['catalog_path_number']);
if(count(path) > 1){
for(i=1;i<count(path);i++){
path_img .="<img src='http://www.chinaz.com/program/2008/1118/./img/sp.jpg'/>";
}
}
echo path_img.cata_img;
echo "<a class='menu' href='http://www.chinaz.com/program/2008/1118/javascrīpt:send_id(".row['catalog_id'].")'>";
echo row['catalog_name']."</a><br>";
path_img="";
if(this->sun_catalog(row['catalog_id'])){
hidden_div="style='display:none'";
echo "<div id='div".row['catalog_id']."' ".hidden_div.">";
this->catalog_show(row['catalog_id']);
echo "</div>";
}
}
}
}
private function sun_catalog(uid){//判断是否有子分类
sql="SELECT * FROM ".this->catalog_dbname. "
WHERE catalog_uid=". uid ."
ORDER BY catalog_id ";
result=mysql_query(sql,this->links) or die("错误: 第".__LINE__."行<br>".mysql_error());
if(mysql_num_rows(result) > 0){
return true;
}else{
return false;
}
}
function catalog_add(uid,name){
//获取父id的亲缘树
this->connect();
sql="SELECT * FROM ".this->catalog_dbname."
WHERE catalog_id='".uid."'";
result=mysql_query(sql,this->links)
or die("错误: 第".__LINE__."行<br>".mysql_error());
row=mysql_fetch_assoc(result);
fid_path_number=row['catalog_path_number'];//id的数字亲缘树
fid_path_char=row['catalog_path_char'];//id的字符亲缘树
//插入数据 先插入行->再找到最新插入的id, 在依据这个id进行修改
sql="INSERT INTO ".this->catalog_dbname."(catalog_uid,catalog_name)
VALUES(".uid.",'".name."')";
result=mysql_query(sql,this->links)
or die("错误: 第".__LINE__."行<br>".mysql_error());
catalog_id=mysql_insert_id();//获取自己的id
catalog_path_number=fid_path_number.":".catalog_id;//得到自己的数字亲缘数
catalog_path_char=fid_path_char.":".name;//得到自己的字符亲缘数
sql="UPDATE '".this->catalog_dbname."'
SET
catalog_path_number='".catalog_path_number."',
catalog_path_char='".catalog_path_char."'
WHERE
catalog_id=".catalog_id;
mysql_query(sql,this->links)
or die("错误: 第".__LINE__."行<br>".mysql_error());
}
function catalog_del(id){
this->connect();
sql="DELETE FROM ".this->catalog_dbname."
WHERE catalog_id=".id;
mysql_query(sql,this->links)
or die("错误: 第".__LINE__."行<br>".mysql_error());
}
function catalog_set(id,name){
this->connect();
sql="UPDATE ".this->catalog_dbname."
SET
catalog_name='".name."'
WHERE
catalog_id=".id;
mysql_query(sql,this->links)
or die("错误: 第".__LINE__."行<br>".mysql_error());
}
}
?>
[/CODE]
以上所分享的是关于PHP实例:PHP无限极分类,下面是编辑为你推荐的有价值的用户互动:
相关问题:php 递归问题,想要将数据按照无限极分类的样式显...
答:首先 将json 解码成数组, 用json_decode 函数 注意 一定要加上第二个参数 否则他会返回一个对象。接下来就是地递归了。这是一个最简单的递归只要逐个遍历即可。 下面是完整的代码: $data= json_decode($str,true);$options = getChildren($dat... >>详细
相关问题:php递归问题(无限极分类)
答:foreach本身就相当于判断了啊,当$arr数组非空时foreach会遍历并递归访问子节点,但是对于叶子结点,$arr数组是空的,根本不会被foreach,此时直接return了。明白? >>详细
相关问题:php递归无限极分类怎么弄
答:给个函数你,调用get_category()就是一个数组格式的结果 function get_category($parent_id=0){ $arr=array(); $sql = "select * from category where parent_id=$parent_id";//查询子级数据 $result = array(a_object,b_object,,,)=sql_query($... >>详细
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
