Welcome Guest, Not a member yet? Register   Sign In
Undefined property
#1

I think the program is correct, but it appears that it is an error. Please someone help me.

A PHP Error was encountered
Severity: Notice
Message: Undefined property: mysqli::$ProductID
Filename: controllers/ProductsUI.php


CI_Model:
PHP Code:
function get_product(){
 
      $this->load->database();
 
      return $this->db->get('product');
 
  

CI_Controller:
PHP Code:
$str '';
 
       $this->load->model('Product');
 
       foreach($this->Product->get_product() as $row){
 
           $str += 'tr role="row">
            <td>'
.$row->ProductID.'</td>
            <td>'
.$row->Product_Name.'</td>
            <td>'
.$row->Cost.'</td>
            <td><button>แก้ไข</button></td>
            <td><button>ลบ</button></td>
            </tr>'
;
 
       
Reply
#2

maybe $row->ProductID should be $row->productid
Simpler is always better
Reply
#3

The problem is this line doesn't return what you think it does

PHP Code:
return $this->db->get('product'); 

You need to Generate Query Results from the returned value - they cannot be read directly. You need something along these lines

PHP Code:
$this->load->model('Product');
$rows $this->Product->get_product()->result(); 
foreach(
$rows as $row){
... 


Or, you could have the model return an actual result set

PHP Code:
function get_product()
{
 
      $this->load->database();
 
      return $this->db
                        
->get('product')
 
                       ->result();



Then your controller code would work as shown in your original post.
Reply
#4

(This post was last modified: 12-16-2018, 05:46 PM by suchanon.)

Thank for dave friend.
i use this code.
PHP Code:
$rows $this->Product->get_product()->result(); 
The program runs through some time, but this problem is offline.

A PHP Error was encountered
Severity: Warning
Message: A non-numeric value encountered
Filename: controllers/ProductsUI.php
Line Number: 32
Backtrace:
File: C:\xampp\htdocs\accounting\application\controllers\ProductsUI.php
Line: 32
Function: _error_handler



PHP Code:
<td>'.$row->Cost.'</td
Reply
#5

I had not looked closely at the code in the loop. Here's my opinion on how it should be written

PHP Code:
foreach($this->Product->get_product() as $row)
{
 
   $str .= "tr role='row'>
    <td>
{$row->ProductID}</td>
    <td>
{$row->Product_Name}</td>
    <td>
{$row->Cost}</td>
    <td><button>แก้ไข</button></td>
    <td><button>ลบ</button></td>
    </tr>"
;

Reply
#6

dave friend
The result is the same.
Reply
#7

(12-17-2018, 08:22 PM)suchanon Wrote: dave friend
The result is the same.

Did you change

PHP Code:
$str += 'tr role="row"> 

to

PHP Code:
$str .= "tr role='row'> 

Look closely they are not the same. The most important bit being $str += changed to $str .=
Reply
#8

Thank you dave friend.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB