데이터베이스 응용 프로그램에 codeigniter를 사용하고 있습니다. codeigniter 데이터베이스 클래스에서 사용자 정의 쿼리에 get_where를 사용할 수 있는지 확실하지 않습니다. 내가Codeigniter에서 사용자 지정 쿼리를 사용할 때 어디에서 사용합니까?
function getVehicles($model='',$varient='')
{
if($model!='')
{
$q=$this->db->query("select model,varient,(select color from mtbl_colors where
mtbl_colors.colorid=mtbl_vehicles.colorid) as color from mtbl_vehicles
where model='$model'")->result();
return $q;
}
elseif($varient!='')
{
$q=$this->db->query("select model,varient,(select color from mtbl_colors where
mtbl_colors.colorid=mtbl_vehicles.colorid) as color from mtbl_vehicles
where varient='$varient'")->result();
return $q;
}
}
, 나는 쿼리를 사용하고 where 절을 사용하여 위를 필터링 할 경우
이이 내가 있어야 할 곳에, 단지 예 지금 내 쿼리
$this->db->query("select model, varient, (select color from mtbl_colors where mtbl_colors.colorid=mtbl_vehicles.colorid) as color from mtbl_vehicles");
입니다 각 조건에 대한 모든 조건을 작성하십시오. 그래서, 나는 지금 사용하고있는 것보다 더 쉬운 여러 가지 조건을 달성 할 수있는 codeigniter에서 어떤 것을 놓칠 수 있습니다.
편집 ::::
내가 같은 시도 @Yan에서 제안이 내 의도가 있다는
"잘못된 열 값 Aarray"를 말하는 데이터베이스 오류가 발생
function getVehicles($where_clause='',$where_value='') {
$sql = "select model,varient,(select color from mtbl_colors where
mtbl_colors.colorid=mtbl_vehicles.colorid) as color from mtbl_vehicles";
$where_clause=array("varient", "model", "colorid");
$where_value=array("MAGNA 1.4", "SANTRO", "3")
if (!empty($where_clause) && !empty($where_value)) {
$sql .= " where $where_clause = ?";
return $this->db->query($sql, $where_value)->result();
}
return false;
}
를 다음과 후 내 필터 옵션에 따라 결과를 생성하기 위해 여러 조건을 구현하십시오. 이 방법을 사용하여
$sql = "select model,varient,(select color from mtbl_colors where
mtbl_colors.colorid=mtbl_vehicles.colorid) as color from mtbl_vehicles";
$where_condition = '';
if (!empty($model)) {
$sql .= " where model = ?";
$where_condition = $model;
}
elseif (!empty($varient)) {
$sql .= " where varient = ?";
$where_condition = $varient;
}
if (!empty($where_condition)) {
return $this->db->query($sql, $where_condition)->result();
}
return false;
입력을 탈출 :
당신은 CodeIgniter의 문서에서 이것에 대해 찾을 수 있습니다 [HTTP : //ellislab.com/codeigniter/user-guide/database/queries.html](http://ellislab.com/codeigniter/user-guide/database/queries.html) – machineaddict