All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
创建表头固定,表体可滚动的GridView_[Asp.Net教程]
在网页中插入媒体播放器详细参考
简单介绍,ASP.NET,中的运算操作符_.net资料_编程技术
Sql,server一些常见性能问题的总结_[SQL,Server教程]
构成Delphi工程的文件:工程文件
让你的.NET程序兼容不同版本的Dll文件_[Asp.Net教程]
系统安全之Apache服务器实现用户验证_[PHP教程]
delphi中使用游标处理数据
.net用OleDb方式操作excel_[Asp.Net教程]
PHP技巧:PHP对GB编码动态转UTF-8几种方法评测_[PHP教程]
Reading number is top 10 pictures
姑娘手慢了,已经走光了
明星与豪宅
人美胸美腿更美1
Sora aoi after swimming
A man's favorite things9
英雄联盟超神十连杀截图
Tie a large font of mouse
Street street fighting
Beautiful Japanese beauty(漂亮的日本美女)2
So beauty, will let you spray blood6
Download software ranking
Red cliff
C语言教程TXT
小黑猫大战两米大花蛇
Call Of Duty2
Tram sex maniac 2 (H) rar bag18
双旗镇刀客B
linux初级教程
Boxer vs Yellow3
Unix video tutorial9
好色的外科大夫
归海一刀 published in(发表于) 2014/2/10 6:51:27 Edit(编辑)
两行代码搞定多级关联搜索_[PHP教程]

两行代码搞定多级关联搜索_[PHP教程]

两行代码搞定多级关联搜索_[PHP教程]


/*
Name: Search.class.php
Author: Genghonghao
Revisions: 2006/12/16
功能 : 多条件关联查寻类
*/
class Search extends Mysql_Class
{
/**
* dbname:数据库名
* searchfiled:查询的字段名例如:SELECT username,userage,usersex FROM
* termfiled查询的条件的字段,where后面的字段名。例如:如WHERE USERID<>25 AND usersex=1
* termvalue查询条件对应的值和条件符号,例如:=@1@,<>@25@,like '%@com@%'等,最之是条件表达式右侧的东西和termfiled数组一一对应,
* 且下标必需为数字,通常情况下符号右边可能是变量,所以变量的前后一定要加上'@'符号
*
*/
private dbname;
private searchfiled = array();
private termfiled = array();
private termvalue = array();

/**
* 设置所有属性的值,参数为两个属性和其值
*/
public function __construct(dbv,sv,fiv,vv)
{
this->SetPm(dbv,sv,fiv,vv);
}

/**
* 设置所有属性的值
*
*/
public function SetPm(v1,v2,v3,v4)
{
self::__set('dbname',v1);
self::__set('searchfiled',v2);
self::__set('termfiled',v3);
self::__set('termvalue',v4);
}
// * 设置属性的值的函数
public function __set(pmname,value)
{
if(isset(value))
{
this->pmname = value;
}
else
{
return null;
}
}

/**
* 参数id是WHERE 后边跟的第一个字段名用来进行第一次判断
* 参数value是字段id的默认值
* 参数emblem是条件判断的符号,例如>,<,<>等
* 参数last是SQL语句最部分,可以为空
* */
public function GetSearch(id,emblem="<>",emblemvalue=0,last="ORDER BY subtime DESC")
{
termfiled = this->termfiled;
termvalue = this->termvalue;
filenum = count(this->termvalue);
if(count(this->termfiled) != count(this->termvalue))
{
return null;
}
else
{
filed = "";
foreach(this->searchfiled as value)
{
filed .= value.",";
}
fnum = strlen(filed);
filed = substr(filed,0,(fnum-1));
sql = "SELECT ";
sql .= filed;
sql .= " FROM ";
sql .= this->dbname;
sql .= " WHERE {id}{emblem}{emblemvalue} ";
for(i=0;i {
//termvalue[i] = str_replace(" ","",termvalue[i]);
if(!strstr(termvalue[i],"@@") and !strstr(termvalue[i],"\"\"") and !strstr(termvalue[i],"%%"))
{
termvalue[i] = str_replace("@","",termvalue[i]);
sql.= "AND {termfiled[i]}{termvalue[i]} ";
}
}
if(!empty(last))
{
sql.=last;
}
// * Execute为父类中的数据据库操作方法,返回的值是数组!
return parent::Execute(sql);
}
}
}
?>
实例:
include_once('include/common.inc.php');
include_once('include/Search.class.php'); // 调用这个文件
table = "tax_codex"; //查寻的数据库表名
filedd = array('Title','Text'); //要查寻的字段
term = array('Click','City','Title'); // 要查寻的条件字段
termv = array('>@0@','="@上海@"',' LIKE "%@中国@%"'); // 要查寻的条件
objsql = new Mysql_Class();
objsearch = new Search(table,filedd,term,termv); // 实例化这个类
print_arr = objsearch->GetSearch('CodexId',"<>","0","ORDER BY SubTime DESC"); // 调用类中方法行到结果数组
print_r(print_arr); // 打印出数组中的值.
?>
来源:网络





添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.