2012-03-13 4 views
0

와 form_dropdown 채우기 I 다음 선택 상자가 : 옵션의foreach는 (CodeIgniter를)

<?php echo form_dropdown('select-something',$options); ?> 

나는 내가 $ 옵션 배열에 추가하여 한 쿼리의 결과를 표시하기 위해 노력하고 있습니다. 예 :

$options = array(); //which should be like 'option1'=>'foo', 
foreach($queryExample->result() as $example){ 
    $options[$example->id] = $example->name; 
} 

것은 form_dropdown 나에게 오류를주고있다 :

Cannot use object of type stdClass as array... 
+0

Travis, shure 필요할 경우 이동하십시오. –

+0

'$ queryExample'을 설정하는 곳에 코드를 게시하십시오. – Catfish

+0

파일 이름과 줄 번호를 포함한 전체 오류 메시지는 무엇입니까? –

답변

0

$this->db->result()이 개체를 반환합니다. $this->db->result_array()을 사용하여 행을 배열로 가져 오면 반복이 쉬워집니다.

+0

개체를 반복 할 수 있지만 이는 부적절합니다. –