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.

Was it helpful?

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
}

OTHER TIPS

$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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top