2013-09-25 2 views
2

안녕하세요 데이터베이스에서 레코드를 검색하려고하지만 여러 필드에서 "심각도 : 경고 메시지 : 잘못된 문자열 오프셋"오류가 계속 발생합니다. 잘못된 문자열 오프셋 codeigniter

여기
<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class View_Logs extends CI_Controller { 

function View_Logs() 
{ 
    parent::__construct(); 
} 

function Logs(){ 
    $id = $this->uri->segment(3); 

    $this->load->model('log_listmodel'); 
    $this->log_listmodel->log_list_get($id);  
} 
} 
?> 

여기 여기

<table class="list_header" bgcolor="#ffffff" border="0" width="1020px" cellpadding="4px"> 

      <?php foreach($query as $row): ?> 
      <tr> 
       <td><b>Updated</b></td> 
       <td><?php echo $row['id'];?>.</td> 
       <td><?php echo $row['new_testing_reason'];?></td> 
       <td><?php echo $row['new_applicant_name'];?></td> 
       <td><?php echo $row['new_authorizer_name'];?></td> 
       <td><?php echo $row['new_received_by'];?></td> 
       <td><?php echo $row['new_test_required'];?></td> 
       <td><?php echo $row['new_laboratory_number'];?></td> 
       <td><?php echo $row['log_date'];?></td> 
       <td><?php echo $row['who'];?></td> 
      </tr> 
      <?php endforeach; ?> 
     </table> 
+1

당신이 점점 오류를 변경해야합니까? –

+0

현재 당면한 문제와 관련이 없지만 MVC 구조가 다소 엉망입니다. 당신은 실제로 컨트롤러에서 당신의 의견을 호출해야합니다. ** 문제 ** : 데이터베이스에서 단 하나의 행만 반환하면 'foreach'를 사용하여 뷰의 행 열을 반복합니다. foreach를 제거하고'$ query [ 'id']'와 같은 데이터에 접근하거나 모델에서 데이터를'$ data [ 'query'] = $ results'로 설정하십시오. – Jeemusu

+0

var_dump ($ row)는 무엇인지보고 싶습니다 (액세스하려는 인덱스가있는 배열이어야합니다) –

답변

4

당신은 결과의 첫 번째 행에 $data['query']를 설정 한하지만, 전체 데이터 세트를 하듯이보기에 당신은 그것을 사용하고 있습니다.

그래서 당신은

$data['query']=$results[0]; 

$data['query']=$results; 

또는

$data['query']=$query->result_array(); 
+0

완벽! 이제 잘 돌아 간다. –

0

귀하의 코드의 unproperly 종류의 내보기 페이지 log_list_view.php의 log_listmodel.php

<?php 
class Log_Listmodel extends CI_Model{ 

    function Log_Listmodel() 
    { 
     parent::__construct(); 
    } 

    function log_list_get($id){ 
    $query = $this->db->get_where('test_request_log', array('test_request_id' => $id)); 
    //return $query->result(); 
    $results=$query->result_array(); 


    $data['query']=$results[0]; 
    $this->load->view('logs_list_view',$data); 
    } 
} 
?> 

내 모델의 view_logs.php 내 컨트롤러입니다 구조, 나는 그것을 재구성하고 단순하게 만든다. 희망이 있습니다.

먼저 데이터베이스 lib를로드 할 수 있습니다.

로 이동응용 프로그램/설정/autoload.php 이 다음 라인 자동로드 데이터베이스 라이브러리

/* 
| ------------------------------------------------------------------- 
| Auto-load Libraries 
| ------------------------------------------------------------------- 
| These are the classes located in the system/libraries folder 
| or in your application/libraries folder. 
| 
| Prototype: 
| 
| $autoload['libraries'] = array('database', 'session', 'xmlrpc'); 
*/ 

$autoload['libraries'] = array('database'); 

컨트롤러보기

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class View_Logs extends CI_Controller { 

function View_Logs() 
{ 
    parent::__construct(); 
    $this->load->library('database'); // if you didn`t load 'database' in your autoload.php 
    $this->load->model('log_listmodel'); 
} 

function Logs(){ 
    $id = $this->uri->segment(3); 


    $data['query'] = $this->log_listmodel->log_list_get($id)->result(); 

    $this->load->view('logs_list_view',$data); 
} 
?> 

모델보기

를 찾아
<?php 
class Log_Listmodel extends CI_Model{ 

    function Log_Listmodel() 
    { 
     parent::__construct(); 
    } 

    function log_list_get($id){ 
     return $this->db->get_where('test_request_log', array('test_request_id' => $id)); 

    } 
} 
?> 

보기 모드

<table class="list_header" bgcolor="#ffffff" border="0" width="1020px" cellpadding="4px"> 

      <?php foreach($query as $row): ?> 
      <tr> 
       <td><b>Updated</b></td> 
       <td><?php echo $row->id;?>.</td> 
       <td><?php echo $row->new_testing_reason;?></td> 
       <td><?php echo $row->new_applicant_name;?></td> 
       <td><?php echo $row->new_authorizer_name;?></td> 
       <td><?php echo $row->new_received_by;?></td> 
       <td><?php echo $row->new_test_required;?></td> 
       <td><?php echo $row->new_laboratory_number;?></td> 
       <td><?php echo $row->log_date;?></td> 
       <td><?php echo $row->who;?></td> 
      </tr> 
      <?php endforeach; ?> 
</table> 
+0

'result()'는 결과 집합 전체를 객체로 반환합니다. 배열에서 문자열로의 변환 오류가 발생합니다 '라고 말했다. 또한 클래스와 같은 이름을 가진 메소드 대신'__construct()'를 사용하십시오. php4 –

+0

@DamienPirsy 덕분에 수정 결과를 obj로로드하는 것을 잊어 버렸습니다. –

+0

@Kaii 님이 귀하의 방법을 시도했지만 다른 오류가 발생했습니다. 치명적인 오류 : "구성원이 아닌 함수에서 log_list_get() 멤버 함수 호출" –

관련 문제