$sql0="select * from portals_channel where ch_use=1 and tid=5 and (chid<>31 and chid<>39 and chid<>44 )";
$query0=exequery($connection,$sql0);//<>或!=表示“不等于”,
while($row0=mysql_fetch_array($query0)){
$chid0[]=$row0[chid];//将指定字段放到一个二维数组中
}
$chid0=implode(',',$chid0);//将数组转换为字符串,以便在下面的查询中使用
$query0=exequery($connection,$sql0);//<>或!=表示“不等于”,
while($row0=mysql_fetch_array($query0)){
$chid0[]=$row0[chid];//将指定字段放到一个二维数组中
}
$chid0=implode(',',$chid0);//将数组转换为字符串,以便在下面的查询中使用
print_r($chid0);
$sql="select count(*) from portals_model_article where chid in ($chid0) and a_title like '%$a_title%' and a_approve='2'";//($chid0) 不能表示为(’$chid0‘) 否则会查询错误;
$query=exequery($connection,$sql);
$row=mysql_fetch_array($query);
个人认为 ,将指定字段放到一个二维数组中,适用于sql语句的某一条件有多个选择时 如上chid<>31 and chid<>39
and chid<>44。可以用in子句来取代许多or条件 in(50,70)