最终sql
SELECT * FROM `tf_company` WHERE `status` = 2 AND (`check_box_val` LIKE '%工业或技改投资%' OR `check_box_val` LIKE '%新增首次2000万以上开票%') ORDER BY id desc LIMIT 0,5
案例
$map['a'] =array('like',array('%thinkphp%','%tp'),'OR');
实战
if ($cb1 = $_GET['cb1']) {
$mapOr[] = '%'.$cb1.'%';
$this->assign('cb1', $cb1);
}
if ($cb2 = $_GET['cb2']) {
$mapOr[] = '%'.$cb2.'%';
$this->assign('cb2', $cb2);
}
if ($cb3 = $_GET['cb3']) {
$mapOr[] = '%'.$cb3.'%';
$this->assign('cb3', $cb3);
}
if ($cb4 = $_GET['cb4']) {
$mapOr[] = '%'.$cb4.'%';
$this->assign('cb4', $cb4);
}
if ($cb5 = $_GET['cb5']) {
$mapOr[] = '%'.$cb5.'%';
$this->assign('cb5', $cb5);
}
if ($mapOr) {
$where['check_box_val'] = array('like',$mapOr,'OR');
}
html
<div class="col-lg-6 search-margin">
<label class="checkbox-inline">
<input type="checkbox" id="cb1" name="cb1" <?php if($cb1) {echo "checked";} ?> value="节能环保产业"> 节能环保产业
</label>
<label class="checkbox-inline">
<input type="checkbox" id="cb2" name="cb2" <?php if($cb2) {echo "checked";} ?> value="乡镇工业园区"> 乡镇工业园区
</label>
<label class="checkbox-inline">
<input type="checkbox" id="cb3" name="cb3" <?php if($cb3) {echo "checked";} ?> value="软件和信息服务业"> 软件和信息服务业
</label>
<label class="checkbox-inline">
<input type="checkbox" id="cb4" name="cb4" <?php if($cb4) {echo "checked";} ?> value="工业或技改投资"> 工业或技改投资
</label>
<label class="checkbox-inline">
<input type="checkbox" id="cb5" name="cb5" <?php if($cb5) {echo "checked";} ?> value="新增首次2000万以上开票"> 新增首次2000万以上开票
</label>
</div>
js
if ($("#cb1").is(':checked')) search_str += '&cb1=' + $("#cb1").val();
if ($("#cb2").is(':checked')) search_str += '&cb2=' + $("#cb2").val();
if ($("#cb3").is(':checked')) search_str += '&cb3=' + $("#cb3").val();
if ($("#cb4").is(':checked')) search_str += '&cb4=' + $("#cb4").val();
if ($("#cb5").is(':checked')) search_str += '&cb5=' + $("#cb5").val();