title: select max codeigniter
body: <p>Im trying to get an max value with codeigniter from an table but it isnt working. This is the error i get:</p>
  
  <blockquote>
    <p>Severity: 4096</p>
    
    <p>Message: Object of class CI_DB_mysql_result could not be converted to
    string</p>
    
    <p>Filename: database/DB_active_rec.php</p>
    
    <p>Line Number: 427</p>
  </blockquote>
  
  <p>This is my function:</p>
  
  <pre><code>public function getPeriodeNummer($bedrijf_id) {
      $this-&gt;db-&gt;select_max('id');
      $this-&gt;db-&gt;where('bedrijf_id', $bedrijf_id);
      $result = $this-&gt;db-&gt;get('rapporten');
  
      $this-&gt;db-&gt;select('periode_nummer');
      $this-&gt;db-&gt;where('rapporten_id', $result);
      $query = $this-&gt;db-&gt;get('statistieken_onderhoud');
  
      $data = $query + 1;
  
      return $data;
  }
  </code></pre>
  
  <p>What im trying to do is as followed:</p>
  
  <ol>
  <li>Select the highest <code>id</code> where <code>bedrijf_id</code> = <code>$bedrijf_id</code> from <code>rapporten</code>.</li>
  <li>Select the <code>periode_nummer</code> from <code>statistieken_onderhoud</code> where <code>rapporten_id</code> = the highest <code>id</code> i got from step 1.</li>
  <li>Add 1 to the <code>periode_nummer</code> i got from step 2 and <code>return</code> that number.</li>
  </ol>
  
  <p>Thanks in forward for your help!</p>