|
楼主 |
发表于 2010-3-29 19:38:31
|
显示全部楼层
呃,结贴吧,做了一个超级弱智的判断……
function search_topic($arr1,$space_count) {
//标准SQL语句的记录
//SELECT * FROM topic WHERE title LIKE binary'%回%'
//OR title LIKE binary'% %' OR title LIKE binary'%子%'
//循环语句描述:for ($i=0;$i<=$space_count;$i++)
if ($space_count == 0) {
$a = $arr1['0'];
$sql = "SELECT * FROM topic WHERE title LIKE binary'%$a%'";
} elseif ($space_count == 1) {
$a = $arr1['0'];
$b = $arr1['1'];
$sql = "SELECT * FROM topic WHERE title LIKE binary'%$a%' AND title LIKE binary'%$b%'";
} elseif ($space_count == 2) {
$a = $arr1['0'];
$b = $arr1['1'];
$c = $arr1['2'];
$sql = "SELECT * FROM topic WHERE title LIKE binary'%$a%' AND title LIKE binary'%$b%' AND title LIKE binary'%$c%'";
} elseif ($space_count == 3) {
$a = $arr1['0'];
$b = $arr1['1'];
$c = $arr1['2'];
$d = $arr1['3'];
$sql = "SELECT * FROM topic WHERE title LIKE binary'%$a%' AND title LIKE binary'%$b%' AND title LIKE binary'%$c%' AND title LIKE binary'%$d%'";
} elseif ($space_count == 4) {
$a = $arr1['0'];
$b = $arr1['1'];
$c = $arr1['2'];
$d = $arr1['3'];
$e = $arr1['4'];
$sql = "SELECT * FROM topic WHERE title LIKE binary'%$a%' AND title LIKE binary'%$b%' AND title LIKE binary'%$c%' AND title LIKE binary'%$d%' AND title LIKE binary'%$e%'";
}
//echo $sql;
$query = $this->db->query($sql);
return $query->result();
} |
|