Welcome Guest, Not a member yet? Register   Sign In
Object of class CI_DB_mysql_result could not be converted to string [SOLVED]
#1

[eluser]Asinox[/eluser]
Hi guys, im trying to count register, but i have the next error:
Code:
A PHP Error was encountered
Severity: 4096
Message: Object of class CI_DB_mysql_result could not be converted to string
Filename: controllers/site.php
Line Number: 41

my code
Code:
function columnasTiposBares(){
             $tipos = $this->modsite->tiposBaresColumna();
             foreach($tipos as $tipo):
             $contando = $tipo->tipo;
             $tip[] =  anchor('site/lugares/'.$tipo->tipo,$tipo->tipo)."->".$this->db->query('SELECT COUNT(tipo) as total from negocios where tipo = "'.$tipo->tipo.'"');
             endforeach;
         return  $this->table->make_columns($tip, 3);
      }

What is wrong guys?

Thanks
#2

[eluser]TheFuzzy0ne[/eluser]
Which is line 41?
#3

[eluser]TheFuzzy0ne[/eluser]
OK, I see that this is line 41:
Code:
$tip[] =  anchor('site/lugares/'.$tipo->tipo,$tipo->tipo)."->".$this->db->query('SELECT COUNT(tipo) as total from negocios where tipo = "'.$tipo->tipo.'"');
The problem is that you're trying to use the db_result as a string. You need to extract the string you require from the query first.
#4

[eluser]Asinox[/eluser]
ok, thanks, is working Smile, but how i print the "total" from the query in this line?

$tip[] = anchor('site/lugares/'.$tipo->tipo,$tipo->tipo)." ( ". HERE I NEED THE SUM TOTAL ." )";

Code:
function columnasTiposBares(){
             $tipos = $this->modsite->tiposBaresColumna();
             foreach($tipos as $tipo):
             $contando = $this->db->query('SELECT COUNT(tipo) as total from negocios where tipo = "'.$tipo->tipo.'"');
             $tip[] =  anchor('site/lugares/'.$tipo->tipo,$tipo->tipo)." ( ".$contando->result() ." )";
             endforeach;
         return  $this->table->make_columns($tip, 3);
      }

thanks
#5

[eluser]Asinox[/eluser]
ok, thanks i did it

Code:
function columnasTiposBares(){
             $tipos = $this->modsite->tiposBaresColumna();
             foreach($tipos as $tipo):
             $contando = $this->db->query('SELECT COUNT(tipo) as total from negocios where tipo = "'.$tipo->tipo.'"');
             $fila= $contando->row();
             $tip[] =  anchor('site/lugares/'.$tipo->tipo,$tipo->tipo)." ( ".$fila->total ." )";
             endforeach;
         return  $this->table->make_columns($tip, 3);
      }

Thanks
#6

[eluser]TheFuzzy0ne[/eluser]
Code:
$tip[] =  anchor('site/lugares/'.$tipo->tipo,$tipo->tipo)." ( ".$contando->row()->total ." )"; # this will only work in PHP 5
#7

[eluser]TheFuzzy0ne[/eluser]
Well done. Smile




Theme © iAndrew 2016 - Forum software by © MyBB