2017-04-18 51 views
1
[error page image][1] 

嘗試使用笨象視圖頁面顯示該錯誤消息來獲得非對象的屬性時,在數據庫表中的任何記錄創立請解決我的問題(當沒有記錄獲得非對象的屬性在數據庫形式創立應該被顯示在視圖頁)嘗試使用笨

控制器

public function buyerdetails_form() { 
      $this->load->helper('url'); 

      $result = $this->Profile_model->buyer_details(); 
      $data['c_address']=$result->address; 
      $data['c_pincode']=$result->pincode; 
      $data['c_district']=$result->district; 
      $data['c_city']=$result->city; 
      $data['c_state']=$result->state; 
      $data['c_country']=$result->country; 
      $this->load->view('buyerdetails_form',$data); 

    } 

模型

public function buyer_details() 
{ 
    $this->db->select('*'); 
    $this->db->from('customer_otherdetails'); 
    $this->db->where('customerid_fk', $this->session->id); 
    $query = $this->db->get(); 
    $rows = $query->result(); //so you only have to call result once 
    if($query->num_rows() > 0) 
    { 
     foreach($rows as $row) 
     { 
      //add all data to session 
      $newdataa = array(
       'address' => $row->address, 
       'pincode' => $row->pincode, 
       'city' => $row->city, 
       'district' => $row->district, 
       'state' => $row->state, 
       'country' => $row->country, 
      ); 
     } 
     $this->session->set_userdata($newdataa); 
     //put the return outside the if 
     //return $query->result(); 
    } 
    // return $rows; //this will be an empty array if no data found 
    return $query->row(); 

} 

視圖

<li class="has-sub" > 
          <span>Country</span> 
          <span><?php echo $c_country; ?></span> 
          <a onclick="hideHasSub()" data-toggle="collapse" data-parent="#accordion" href="#collapseone"> 
           <span class="profile-edit" onclick="" >Edit</span></span> 
          </a> 
          <div style="clear:both;"></div> 
         </li> 
         <div class="sub"> 
          <div class="panel-body "> 
           <div class="row"> 
            <div class="col-lg-8 col-lg-offset-2 text-center"> 

              <label style="display:inline;">Country</label> 
              <input type="text" name="id" value="<?php echo $this->session->id; ?>" /> 
              <input style="width:50%;height:20px;" type ="text" class="form-control" name="country" value="<?php echo $c_country; ?>"/></br> 
              <p style="font-size: 12px;"><b>Note:</b> Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p> 
              <input type="submit" value="Save" class="btn btn-success" style="width:70px;"> 
<!--           <button type="button" style="margin:0 10px;">Save</button>--> 

             <button type="button" class="btn btn-warning cancel-name " >Cancel</button> 
            </div> 
           </div> 
          </div> 
         </div> 
+0

你需要使用'isset()函數'檢查對於空變量或空變量 –

+0

在打印變量之前,您應該使用is_array($ yourvar)函數,如果有值那麼它將顯示您可以在其他語句中顯示'找不到記錄'。 –

+0

@ImmortalDude謝謝你的代碼工作 –

回答

0

改變這個模型中的 $rows = $query->result_array();

,還可以使用if(isset){}檢查空