Welcome Guest, Not a member yet? Register   Sign In
method chaining
#1

[eluser]praveenarya[/eluser]
hi all,
using method chaining system i have written like
Code:
$this->db->select('*')->from('tbl_orders')->where('status=0 group by ref_id order by id desc');

                  $query = $this->db->get();

but i am getting error
Unknown column 'status=0' in 'where clause'
the quotation should be 'status'=0 instead it is placing as above

thanks in advance
#2

[eluser]davidbehler[/eluser]
Try this:
Code:
$this->db->select('*')->from('tbl_orders')->where('status', 0)->group_by('ref_id')->order_by('id', 'desc');
#3

[eluser]praveenarya[/eluser]
hi thanks for quick response though query is right i am getting error
A PHP Error was encountered
Severity: 4096

Message: Object of class CI_DB_mysql_result could not be converted to string

Filename: views/left.php

thanks in advance
#4

[eluser]davidbehler[/eluser]
What are doing with the result in your view?

Code:
$result = $this->db->get(); // this returns an object
$result->result_array(); // return an array of the selected rows
#5

[eluser]praveenarya[/eluser]
thank you so much its working fine
#6

[eluser]davidbehler[/eluser]
No problem. Glad I could help
#7

[eluser]praveenarya[/eluser]
hi sorry for trouble,i have changed few settings for my admin control panel and now i see this error
Call to undefined method CI_DB_mysql_driver::result_array() in D:\wamp\www\shop_codeigniter\system\application\g_cpanel\views\left.php on line 45

thank you in advance
#8

[eluser]davidbehler[/eluser]
This usually happens if your select returns no rows.
Try this
Code:
if($result->num_rows() > 0)
{
   return $result->result_array();
}
else
{
   return FALSE; // or return array(); or whatever you need
}
#9

[eluser]praveenarya[/eluser]
i have written as follows
Code:
$result=$this->db->select('*')->from('tbl_orders')->where('status', 0)->group_by('ref_id')->order_by('id', 'desc');
              
                    if($result->num_rows() > 0){

echo "hiiiii";
}else {
echo '0';
}
{
but i am getting error
Call to undefined method CI_DB_mysql_driver::num_rows()
thanks in advance
#10

[eluser]davidbehler[/eluser]
You forgot to actually get the result.

So add this to your chain the first line:
Code:
->get();




Theme © iAndrew 2016 - Forum software by © MyBB