1 $this->load->model (' Station/station_model ', ' Station ');2 //East3 // North4 $this->station->set_where (' Isdel ', 0); 5 //even table query area6 $this->station->list_attributes = ' Region.text as sitone,station. North,station. East,station.state,station.stabianhao,station.staname,station.siteonename,station.sitetwoname,station.sitename , Station.statype,station.settime,station.staid ';7 $this->station->Join(' Region ', ' Region.linkageid = Station.sitetwoname ', ' left ');8 if($type! = ' All ') {9 $this->station->set_where (' Station.state ',$type);Ten } One A $this->station->set_where (' (Station.sitetwoname '),$sitearr, ' where_in '); - $this->station->set_where (' Station.siteonename ',$sitearr, ' or_where_in '); - $this->station->set_where (' 1 = 2) and 1 ', ' 1 ', ' or_where_in '); the - $data=$this->station->Get_stewhere_all (); - Echo $this->db->last_query (); die;
This generates a SQL that is
1 SELECT2' Dz_region '. 'text` as' Sitone ',3 ' Dz_station '. ' North ',4 ' dz_station '. ' East ',5 ' Dz_station '. ' State ',6 ' dz_station '. ' Stabianhao ',7 ' dz_station '. ' Staname ',8 ' dz_station '. ' Siteonename ',9 ' dz_station '. ' Sitetwoname ',Ten ' dz_station '. ' SiteName ', One ' dz_station '. ' Statype ', A ' dz_station '. ' SetTime ', - ' dz_station '. ' Staid ' - from the ' Dz_station ' - Left JOIN' Dz_region ' on' Dz_region '. ' Linkageid '=' dz_station '. ' Sitetwoname ' - WHERE -' Isdel '= 0 + and ( -' Dz_station '. ' Sitetwoname 'inch ( + '1', A '199', at '203', - '197', - '209', - '208' - ) - OR' Dz_station '. ' Siteonename 'inch ( in '1', - '199', to '203', + '205', - '211', the '197', * '209', $ '208'Panax Notoginseng ) - OR 1 = 2 the ) + and 1 inch('1')
Above
If you do not use my method, the generated SQL is
SELECT ' dz_region ', ' text ' as ' sitone ', ' dz_station '. ' North ', ' dz_station '. ' East ', ' dz_station '. ' state ', ' dz_station '. ' Stabianhao ', ' dz_station '. ' Staname ', ' dz_station '. ' Siteonename ', ' dz_station '. ' Sitetwoname ', ' dz_station '. ' SiteName ', ' dz_station '. ' Statype ', ' dz_station '. ' SetTime ', ' dz_station '. ' Staid ' from ' dz_station ' left JOIN ' dz_region ' On ' dz_region '. ' Linkageid ' = ' dz_station '. ' Sitetwoname ' WHERE ' isdel ' = 0AND ' dz_station '. ' Sitetwoname ' in (' 1 ', ' 199 ', ' 203 ', ' 205 ', ' 197 ', ' 209 ', ' 208 ') OR ' dz_station '. ' Siteonename ' in (' 1 ', ' 199 ', ' 203 ', ' 205 ', ' 211 ', ' 209 ', ' 208 ')
Of course this is not satisfied with the demand, as for why not native SQL, because the array is not processed,
The CI framework uses frames to add parentheses, such as like and so on, to add parentheses around the solution