{
if($result_count==1) //判断如果是一个关键段
{
$newstring_search=$newstring2[0]; //$newstring_search 是关键字
$sql="SELECT *
FROM `$table`
WHERE ";
$sql_add="";//新增加字段
foreach ($new_field as $key => $value)
{
if($key==0)
{
$sql_add=$sql_add."`".$value."` LIKE '%".$newstring_search."%'";
}
else
{
$sql_add=$sql_add." OR `".$value."` LIKE '%".$newstring_search."%'";
}
}
$sql=$sql.$sql_add;
}
if($result_count>1) //判断如果是多个关键段(多个关键字)===
{
$sql="SELECT *
FROM `$table`
WHERE ";
$sql_add="";//新增加字段
foreach ($new_field as $key => $value)
{
if($key==0) //遇到$new_field[0]时候 例:`a` LIKE '%1%' OR `a` LIKE '%2%' OR `a` LIKE
'%3%'
{ //嵌套 foreach
foreach ($newstring2 as $key2 => $value2)
{
if($key2==0)
{
$sql_add=$sql_add."`".$value."` LIKE '%".$value2."%'";
}
else
{
$sql_add=$sql_add." OR `".$value."` LIKE '%".$value2."%'";
}
}
//嵌套 foreach