Question

How can I make this right?

From Model page

$query = $this->db->query("SELECT masters from table2 where table_id='table2-G' AND psced_id='58'");      
  //masters in an Integer type

if ($query !=0 ){
  //code for dividing

but I get an error

Message: Object of class CI_DB_postgre_result could not be converted to int

What I want to get here is that if the value of $query is equal to 0, I could divide.

Était-ce utile?

La solution

I added a comment to the original question, but to make it official:

You can check the number of rows returned by the query like so...

if ($query->num_rows() > 0) {
   // your code
}

Autres conseils

$query is an array, probably an array of arrays, so you need to check its count first, then get the element. Once you have the single element you can check it for 0 and do your divide.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top