CodeIgniter Forums

Full Version: call to undefined function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]suku[/eluser]
please can i get help from anyone,
i got problem in this code,it says,
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: rows

Filename: price/view.php

Line Number: 42

Fatal error: Call to a member function num_rows() on a non-object in C:\xampp\htdocs\work\application\views\price\view.php on line 42


the code is here,

[removed][removed]
[removed]
function callme(id, value)
{
$("#span"+id).after('&lt;form action="&lt;?php echo base_url(); ?&gt;index.php/price/edit/' +id+'" method="post" id="frmEditPrice" name="frmEditPrice" &gt; <label>Price :&lt;input type="text" id="price" name="price" value='+ value +' /&gt;&lt;/label>&lt;input type="submit" value="submit" id="cmdSubmit" /&gt;&lt;/form>');
}
[removed]
&lt;/head&gt;

&lt;body&gt;
<table>
&lt;?php if($rows->num_rows()!=0 ):?&gt; //here it says error

<tr>
<td></td>
<td>
&lt;form action="&lt;?php echo base_url().'index.php/price/insert'; ?&gt;" method="post" id="frmPrice" name="frmPrice"&gt;

<label>Price :
&lt;input type="text" id="price" name="price" /&gt;
</label>
&lt;input type="submit" value="Ok" /&gt;
&lt;input type="hidden" id="hdId" name="hdId" /&gt;

&lt;/form&gt;
</td>
<td></td>
</tr>
</table>


thanks,

El Forum

[eluser]weboap[/eluser]
CI is telling you the view didn't receive the query var , $rows is not set
probably need to do something in your controller like

Code:
$data->rows = $this->mymodel->myfunction(); // pull data from db

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


can you post the relevant part of your controller and model,
and also personally i will keep that test in the model, then return either the $rows or false to the controller then send it to the view in the view instead of testing on
Code:
count()
i will test if false mean no data.
hope it help


NOTE: can you use the tag --- code --- when you post code to the forum. thanks

El Forum

[eluser]suku[/eluser]
&lt;?php
class Price extends CI_Controller {

public function __construct()
{
parent::__construct();

$this->load->helper('url');
// Your own constructor code
}
function index()
{
echo 'hello';
}
function display_view()
{
$this->load->view('price/view');
}

function edit($id)
{
$this->output->enable_profiler(TRUE);
$price=$this->input->post('price');
$data=array(

'fld_price'=>$price
);

$this->load->model('price_model');
$this->price_model->edit($data);

}

function insert()
{


$price=$this->input->post('price');
$id=$this->input->post('hdId');

$data = array('fld_id'=>$id,

'fld_price'=>$price
);

$this->load->model('price_model');
$this->price_model->insert($data);
//$this->load->select();
}
function select()
{

$this->load->model('price_model');
$data['rows']=$this->price_model->select();
$this->load->view('price/view',$data);

}
function delete($id)
{
//print_r($id);
$this->load->model('price_model');
$this->price_model->delete($id);
}
function update($id)
{
$price=$this->input->post('price');
print_r($id);
$data = array(

'fld_price'=>$price
);
print_r($id);

$this->load->model('price_model');
$this->price_model->update($id,$price);
/* $this->load->view('price/view',$data);*/


}

}
?&gt;

&lt;?php
class Price_model extends CI_Model
{

function __construct()
{
// Call the Model constructor
parent::__construct();
}
function insert($data)
{
$this->db->insert('tbl_price',$data);
}
function select()
{
$query = $this->db->get('tbl_price');
return $query;

}
function delete($id)
{
$this->db->where('fld_id', $id);
$this->db->delete('tbl_price');


}
function edit($data)
{

$this->db->set('fld_price',$price);
$this->db->where('fld_id', $id);
$this->db->insert('tbl_price');

}

}

El Forum

[eluser]Chathuranga Tennakoon[/eluser]
Code:
$this->load->model(‘price_model’);
should be corrected as
Code:
$this->load->model(‘Price_model’);

El Forum

[eluser]Aken[/eluser]
The model name is not the issue, they do not need to be capitalized.

You need to use [ code ] tags, we can't read it without it. You also need specify the actual errors.