hi [color="#225985"]johnny[/color],
i have problem with get_where function.if you have solution please let me know.i am getting error
[b]Fatal error[/b]: Call to a member function get_where() on a non-object in [b]C:\xampp\htdocs\myproject\application\models\catmodel.php[/b] on line [b]13[/b]
code for Model is
<?php
class catmodel extends CI_Model
{
function __construct()
{
parent::__construct();
}
function getcat($id)
{
$data=array();
$query=$this->db->get_where('categories',array('cat_id' => $id),1)->result();
if($query->num_rows()>0)
$data= $query->row_array();
$query->free_result();
return $data;
}
function getCats()
{
$data=array();
$query=$this->db->get('categories');
if($query->num_rows>0)
{
foreach($query->result_array() as $row)
{
$data[]=$row;
}
}
$query->free_result();
return $data;
}
}
------------------------------------------------------
Controller
<?php
class Test extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->library('parser');
}
function index()
{
$data['title']="Test Website";
$data['header']="Test Header";
$data['body']="Test Body";
$this->load->model('catmodel');
$this->load->model('prodmodel');
$id='1';
$mycat=$this->catmodel->getcat($id);
$data['mycat']=$mycat['cat_name'];
$data['allcats']=$this->catmodel->getCats();
$myprod=$this->prodmodel->getProd($id);
$data['myprod']=$myprod['prod_name'];
$data['allprod']=$this->prodmodel->getProds();
$this->parser->parse('testpage',$data);
}
}?>
-------------------------------------------
view
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<h4>A Category With an ID of 1</h4>
<p>{mycat}</p>
<h4>All Category List</h4>
<ul>
<?php foreach($allcats as $cat){?>
<li>
<?= $cat['cat_name']; ?>
</li>
<?php } ?>
</ul>
<hr />
<h4>A Product With an ID of 1</h4>
<p>{myprod}</p>
<h4>All Product List</h4>
<ul>
<?php foreach($allprod as $product){?>
<li>
<?= $product['prod_name']; ?>
</li>
<?php } ?>
</ul>
</body>
</html>
Is there any mistake,please correct it.
Thanks in advance.
Malli
problem with get_where
Started by malli, 25 July 2012 - 20:11 PM
- Single Page
Posted 25 July 2012 - 20:11 PM
Posted 26 July 2012 - 07:01 AM
Hi, malli!
You have forgotten to load the database library. So, your model doesn't know about get_where() function.
P.S. When you share your code, please, use the "code" button in order we have more readable information. And I think that your question is more for the "I have a question" section (or "General" section) rather than for "Bugs & issues", where we post info about bugs of grocery CRUD library.
Best regards!
You have forgotten to load the database library. So, your model doesn't know about get_where() function.
P.S. When you share your code, please, use the "code" button in order we have more readable information. And I think that your question is more for the "I have a question" section (or "General" section) rather than for "Bugs & issues", where we post info about bugs of grocery CRUD library.
Best regards!