2013-02-14 40 views
1

當我使用var_dump($ row);在我的代碼上te網頁上的線說apprie說資源(29,mysql鏈接持久化)這意味着什麼劑量?即時通訊新的PHP和codeignite所以使它簡單,如果你可以,非常感謝你。資源(29,mysql鏈接持久)

Controller.php這樣

<?php 

class Survay extends CI_Controller{ 

function index() 
{ 
      $data = array(
     'question' => $this->input->post('question'), 
      'answer1' => $this->input->post('answer1'), 
      'answer2' => $this->input->post('answer2'), 
      'answer3' => $this->input->post('answer3'), 
      'answer4' => $this->input->post('answer4'), 
      'answer5' => $this->input->post('answer5'), 
      'answer6' => $this->input->post('answer6'), 
      ); 


      if($query = $this->membership_model->get_records()){ 
      $data['records'] = $query; 
      } 

      $this->page(); 

      $this->load->view('survay_view', $data); 

      } 

//pagination 
     function page() 
      { 

      $this->load->library('pagination'); 


      $config['base_url'] = 'http://localhost/admin/index.php/survay/'; 
      $config['total_rows'] = $this->db->get('save_survay')->num_rows(); 

      $config['per_page'] = 1; 
      $config['num_links'] =10; 

      $this->pagination->initialize($config); 
      //print_r($this->uri->segment());die; 

      $data['records'] = $this->db->get('save_survay', $config['per_page'], 
      $this->uri->segment(2,0)); 

      $data['pagination'] = $this->pagination->create_links(); 
      $this->load->view('survay_view', $data); 

      } 
    } 

?> 

view.php

 </head> 
    <body> 


      <h1>Answer</h1> 
      <?php if (isset($records)) : foreach($records as $row) : ?> 

     <div = 'container'> 




      <ul> 
      <?php 
      if (isset($pagination)) 
      { 
      echo $pagination; 
      } 


      ?> 
      <h1><?php echo $row->question; ?></h1> 

      <li><?php echo $row->answer1; ?></li> 
      <li><?php echo $row->answer2; ?></li> 
      <li><?php echo $row->answer3; ?></li> 
      <li><?php echo $row->answer4; ?></li> 
      <li><?php echo $row->answer5; ?></li> 
      <li><?php echo $row->answer6; ?></li> 
      <ul> 

     </div> 

      <?php endforeach; ?> 
      <?php else : ?> 
      <h2>no records were returned</h2> 
      <?php endif; ?> 
    </body> 
</html> 
+0

你可以發佈你的代碼片段嗎? – 2013-02-14 12:09:00

+0

我發佈了代碼 – 2013-02-14 12:18:22

+0

問題在哪裏? – 2013-02-14 12:19:16

回答

0

通告消息:試圖獲得非對象文件名的屬性:視圖/ survay_view.php行號:33

您收到上述錯誤的原因是因爲您試圖訪問保存在$ records數組作爲對象$row->some_variable,並且看起來這個數據不是一個對象。

您正在使用下面的代碼從數據庫中獲取結果:

$data['records'] = $this->db->get('save_survay', $config['per_page'], $this->uri->segment(2,0));

上面的代碼運行在數據庫上查詢,但僅此還生成有用的格式的任何結果。它返回的是一個數組,其中包含有關查詢的各種數據,其中包含結果。

訪問結果作爲對象,你可以按如下調整你的代碼:

$data['records'] = $this->db->get('save_survay', $config['per_page'], $this->uri->segment(2,0))->result();

如果你想要的結果返回一個數組,你可以使用以下命令:

$data['records'] = $this->db->get('save_survay', $config['per_page'], $this->uri->segment(2,0))->result_array();

正如我在評論中提到的,我真的推薦閱讀文檔,尤其是關於Generating Query Results

的頁面
+0

非常感謝你的幫助你從很多頭痛救了我:)我正在閱讀文檔 – 2013-02-14 13:15:28