2013-07-06 2 views
1

만 반환합니다. CI/PHP/development를 처음 사용합니다. 나는이 문제에 갇혔다. 그것은 정말로 기본적인 것처럼 보인다. 그러나 나는 단지 기울인다 그것을 올바르게한다!Codeigniter View는 마지막 행 쿼리

에만 문제가 쿼리의 마지막 행을 표시합니다 내보기는 결과이다

모델 :

$this->db->select('Caption,Description');       
$query = $this->db->get_where('Events', array ('User_iduser' => $user_id)); 
$results = $query->result();        

컨트롤러 :

$this->load->model('get_events_model'); 
$data['results'] = $this->get_events_model->get_events(); 
$this->load->view('main/members_area_form',$data); 

보기 :

<?php foreach($results as $row); { 
echo $row->Caption; 
echo $row->Description; 
} 
?> 

보기에 ...

var_dump($results); 

을하고 그 결과는 다음과 같습니다 : bleshoot 나는 뒀다

array(3) { [0]=> object(stdClass)#18 (2) { ["Caption"]=> string(5) "Color"  ["Description"]=> string(4) "Blue" } [1]=> object(stdClass)#19 (2) { ["Caption"]=> string(5) "Color" ["Description"]=> string(3) "Red" } [2]=> object(stdClass)#20 (2) { ["Caption"]=> string(5) "Color" ["Description"]=> string(5) "Black" } } 

그래서 DB의 쿼리 문제 여전히 foreach 루프는 마지막 행을 표시하고 아무것도 없다 쿼리에서. 내가 도대체 ​​뭘 잘못하고있는 겁니까? 보기 코드에서

답변

4
remove ";" from 
<?php foreach($results as $row); { 

the line will be 
<?php foreach($results as $row) { 

in your case foreach was only looping but your echos was not in foreach. 
after executing foreach 
it was coming to your echo part and echoing last row as foreach already conpleted its loop. 
+0

후 예 그것은 그 것이었다. 현재 작동하고 있으며 모두 의미가 있습니다. 고맙습니다 –

0

보기 :

당신이 당신의 불필요한 세미콜론을 제거해야합니다 ";" foreach는

<?php 
    foreach($results as $row) { 
     echo $row->Caption; 
     echo $row->Description; 
    } 
?>