Home > php教程 > php手册 > 关键字查询类

关键字查询类

WBOY
Release: 2016-06-06 19:34:38
Original
983 people have browsed it

无详细内容 无 /*多关键字查询类*/ class MultiKeySearch//多关键字查询类 { private $Keyword;//查询关键字private $result;//结果function __construct($Keyword,$Datalist,$Field)//查询关键字,数据表{ $this-Keyword=$Keyword; $this-Datalist=$Datalist

/*多关键字查询类*/
  class MultiKeySearch//多关键字查询类
  {
    private $Keyword;//查询关键字
	private $result;//结果
	function __construct($Keyword,$Datalist,$Field)//查询关键字,数据表
	{
	  $this->Keyword=$Keyword;
	  $this->Datalist=$Datalist;
	  $this->Field=$Field;//查询的关键字段
	}
	function DoSql()//查询关键字,取得值
	{
	  $ArrayKeyword=preg_split('/\.|\+| |_/',$this->Keyword);
	  //分割,返回数组.+空格下划线分割。
	  $Query=M($this->Datalist);//实例化模型
	  $conditon="";//条件集合
	  $flag=1;
	  //dump($ArrayKeyword);
	  foreach($ArrayKeyword as $value)
	  {
	    //echo $value;
	    if($flag==1)
	    {
		  $condition.=$this->Field." like '"."%".$value."%'";//模糊查询
		  $flag=0;//首个字段不用加or
		}
		else
		{
		  $condition.=' or '.$this->Field." like '"."%".$value."%'";
		}
	  }
	  //echo $condition;//打印SQL条件语句
	  $this->result=$Query->where($condition)->select();
	  foreach($this->result as &$value)//遍历数组添加引用,
	  {
	    foreach($ArrayKeyword as $keyword)
		{
		  $value['Profession']= str_replace($keyword,"<font color=red>".$keyword."</font>",$value['Profession']);
		}
	  }
	  return $this->result;//返回一个高亮查询结果
	}
	
  }
  /*多关键字查询类END*/
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template