반응형
CodeIgniter의 활성 레코드 메서드를 사용하여 ORDER BY 절을 추가하는 방법은 무엇입니까?
데이터베이스 테이블에서 모든 레코드를 가져올 수 있는 매우 작은 스크립트가 있습니다. 코드는 아래와 같습니다.
$query = $this->db->get($this->table_name);
return $query->result();
이 구문을 사용하여 다음을 추가하려면 어떻게 해야 합니까?ORDER BY 'name'
내 선택 쿼리의 절?
저는 주문을 끝에 조금씩 붙일 때마다 오류가 발생합니다.
나는 믿습니다.get()
함수는 즉시 선택 쿼리를 실행하고 수락하지 않습니다.ORDER BY
매개 변수로서의 조건.조건을 별도로 선언하고 쿼리를 실행해야 할 것 같습니다.시도해 보십시오.
$this->db->from($this->table_name);
$this->db->order_by("name", "asc");
$query = $this->db->get();
return $query->result();
이 코드를 사용하여 단일 쿼리에서 여러 개의 순서를 지정합니다.
$this->db->from($this->table_name);
$this->db->order_by("column1 asc,column2 desc");
$query = $this->db->get();
return $query->result();
간편하고 간편한 기능:
$this->db->order_by("name", "asc");
$query = $this->db->get($this->table_name);
return $query->result();
코드에 'order_by' 절을 추가하고 아래와 같은 모양으로 수정하기만 하면 됩니다.
$this->db->order_by('name', 'asc');
$result = $this->db->get($table);
여기 있습니다.
function getProductionGroupItems($itemId){
$this->db->select("*");
$this->db->where("id",$itemId);
$this->db->or_where("parent_item_id",$itemId);
/*********** order by *********** */
$this->db->order_by("id", "asc");
$q=$this->db->get("recipe_products");
if($q->num_rows()>0){
foreach($q->result() as $row){
$data[]=$row;
}
return $data;
}
return false;
}
언급URL : https://stackoverflow.com/questions/5320395/how-to-add-an-order-by-clause-using-codeigniters-active-record-methods
반응형
'programing' 카테고리의 다른 글
Xcode 7로 전환한 후 앱 크기가 9MB에서 60MB로 커졌는데 해결책이 있나요? (0) | 2023.08.10 |
---|---|
어떻게 하면 호버링되는 동안 부트스트랩 팝오버를 유지할 수 있습니까? (0) | 2023.08.10 |
사용 후 DB Command를 폐기해야 합니까? (0) | 2023.08.10 |
도커 합성을 사용하여 mysql의 기본 문자 집합을 변경하는 방법은 무엇입니까? (0) | 2023.08.10 |
assert(0)의 의미는 무엇입니까? (0) | 2023.08.10 |