php?搜索功能解决办法

WBOY
Release: 2016-06-13 12:25:38
Original
951 people have browsed it

php?搜索功能

根据条件,搜索出符合条件的数据
1.如何实现这个功能?
2.数据多,搜索慢,这些问题要怎么解决??
------解决思路----------------------
1.根据条件生成sql where 条件语句
2.需要搜寻的字段加上索引。

例如:数据库有三个需要搜寻的字段 a b c
首先三个字段都需要加上索引
生成查询语句如下:
$a = $_POST['a'];
$b = $_POST['b'];
$c = $_POST['c'];

$where = array('1=1');
if($a){
    $where[] = " a='".$a."' ";
}
if($b){
    $where[] = " b='".$a."' ";
}
if($c){
    $where[] = " c='".$a."' ";
}

$sqlstr = "select * from table where ".implode('and', $where);
// 执行查询。


?>

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template