title: Retrieve a single row from Codeigniter
body: <p>If I need to retrieve a single row of data from the database, why can't I do this when I want to insert that id into another table:</p>
  
  <pre><code>'user_id' =&gt; $query-&gt;row()-&gt;id
  </code></pre>
  
  <p>Is there any way to do this without a foreach loop if all I want is a single piece of data?</p>
  
  <p>The full code is: </p>
  
  <pre><code>$this-&gt;db-&gt;where('username', $this-&gt;input-&gt;post('username'));
          $query = $this-&gt;db-&gt;get('members');
  
          $data = array(
              'first' =&gt; $this-&gt;input-&gt;post('first'),
              'last' =&gt; $this-&gt;input-&gt;post('last'),
              'email' =&gt; $this-&gt;input-&gt;post('email'),
              'phone' =&gt; $this-&gt;input-&gt;post('phone'),
              'address' =&gt; $this-&gt;input-&gt;post('address'),
              'city' =&gt; $this-&gt;input-&gt;post('city'),
              'state' =&gt; $this-&gt;input-&gt;post('state'),
              'zip' =&gt; $this-&gt;input-&gt;post('zip'),
              'comments' =&gt; $this-&gt;input-&gt;post('comments'),
              'username' =&gt; $this-&gt;input-&gt;post('username'),
              'user_id' =&gt; $query-&gt;row()-&gt;id
          );
  
          $this-&gt;db-&gt;insert('contact', $data);
  </code></pre>