title: codeigniter query
body: <p>I am trying to write CodeIgniter query having MAX, SUBSTRING and CAST together that returns an integer value.. 
  This is what I have in the module passing a prefix (AL, PK etc):</p>
  
  <pre><code>function getMaxIDMatchingPrefix($locationPrefix){ 
   $sql = "SELECT MAX( SUBSTRING( locationID , 3, 11 ) ) 
   FROM items WHERE LEFT( locationID , 2 ) = = ? "; 
   $query = $this-&gt;db-&gt;query($sql, $locationPrefix); 
   return $query; 
  } 
  </code></pre>
  
  <p>This is what I have in the controller to retrieve the integer value (1 or 3 or 114 etc):</p>
  
  <pre><code>$location_max_id = $this-&gt;location_model-&gt;getMaxLocationID($locationPrefix);
  </code></pre>
  
  <p>But I get an error: <strong>Object of class CI_DB_mysql_result could not be converted to string</strong> Can someone please help me with this?</p>