PHP无限分类的例子(包括数据库)转
其他常见的无限分类方法:
1,简单的通过递归查询加目录path字段的无限分类
缺点:查询数据库次数太多,不方便其他操作,比如删除节点。添加节点,移动节点
2,左右值无限分类,预排序二叉树
缺点:操作繁琐,数据库冗余,且添加删除修改都要进行左右值更新
本分类方法的优势:
1,数据库结构简单,只有 cid parentid name 三个字段,无任何冗余字段
2,不使用递归查询,所有操作只需一条sql语句
3,所有数据在读取一次数据库后,在数组内进行分析处理,节省数据库服务器资源
创建数据库以及表:
CREATE DATABASE `sortclass`DEFAULT CHARSET utf8;
CREATE TABLE IF NOT EXISTS `class` (
`cid` mediumint(8) unsigned NOT NULL auto_increment,
`pid` mediumint(8) unsigned NOT NULL,
`cname` varchar(50) NOT NULL,
PRIMARY KEY (`cid`),
KEY `pid` (`pid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
处理文件示例:
<?php
header("Content-type: text/html; charset=utf-8");
//连接数据库
$link = mysql_connect('localhost','root','eric') or die(mysql_error());
mysql_select_db('sortclass',$link);
//无限分类类库
class SortClass{
var $data = array();
var $child = array(-1=>array());
var $layer = array(-1=>-1);
var $parent = array();
var $link;
var $table;
function SortClass($link, $table){
$this->setNode(0, -1, '顶极节点');
$this->link = $link;
$this->table = $table;
$node = array();
$results = mysql_query('select * from '.$this->table.'',$this->link);
while($node = mysql_fetch_assoc($results)){
$this->setNode($node['cid'],$node['pid'],$node['cname']);
}
}
function setNode ($id, $parent, $value){
$parent = $parent?$parent:0;
$this->data[$id] = $value;
$this->child[$id] = array();
$this->child[$parent][] = $id;
$this->parent[$id] = $parent;
$this->layer[$id] = !isset($this->layer[$parent])? 0 : $this->layer[$parent] + 1;
}
function getList (&$tree, $root= 0){
foreach ($this->child[$root] as $key=>$id){
$tree[] = $id;
if ($this->child[$id]) $this->getList($tree, $id);
}
}
function getValue ($id){return $this->d
相关文档:
<?php
/*
* 名称 : MySQL数据库基本操作
* 作者 : pjx
* 版本 : v 2010/02/25 v 1.0
* 说明 : 该类用于对MySQL做一些简单的操作
* 示例 :
* 实例 => $db = new DB_MYSQL($database),打个$database数据库
* 查询数据库 => $db->query($sql_str),查询$sql_st ......
首先要了解sql语句
$SQL="delete from `PHP100` where id in (1,2,4)";
表单大概是:
<form action="" method="post">
<input name="ID_Dele[]" type="checkbox" id="ID_Dele[]" value="1"/>
<i ......
[part1] http://download.csdn.net/source/2076258
[part2] http://download.csdn.net/source/2076272
[part3] http://download.csdn.net/source/2076276
[part4] http://download.csdn.net/source/2076283
[part02-04] http://www.ytgps.com/Images/nginx.rar
本文件体积过大分4个包,php-cgi+mysql+nginx.7z ......
if(validatorImage("d:\b.jpg"))
echo '是个低俗图片<br />';
else
echo '不是低俗图片<br />';
function validatorImage($fileName){
$image = getImage($fileName);
$width = ImagesX($image);
$height = ImagesY($image);
$ycb = 0;
for($y=0;$y<$height;$y++){
for($x=0;$x<$widt ......
PHP中设计模式的学习笔记
设计模式(Design Pattern)是面向对象设计中反复出现的问题的解决方案,设计模式是一种比一般类的设计更加抽象的一种思想,
它往往涉及到多个类的定义和使用。
在PHP的开发过程中,经常使用到得设计模式包括:简单工厂模式、单元素模式、观察者模式、命令模式、策略模式以及MVC模式等。
/ ......