title: How to find specific row in MySQL query result?
body: <p>So I do this to retrieve my entire table:</p>
  
  <pre><code>$result = mysql_query( 'SELECT * FROM mytable' );
  </code></pre>
  
  <p>Then, in another part of my PHP-page, I do another query (for a specific row):</p>
  
  <pre><code>$result2 = mysql_query( 'SELECT * FROM mytable WHERE id = ' . $id );
  $row = mysql_fetch_array( $result2 );
  </code></pre>
  
  <p>So, I'm performing two querys. However, I don't really have to do that, do I? I mean, the row that I'm retrieving in my second query already is present in <code>$result</code> (the result of my first query), since it contains my entire table.</p>
  
  <p>Therefore, instead of doing the second query, I would like to extract the desired row from <code>$result</code> directly (while keeping <code>$result</code> itself in tact).</p>
  
  <p>How would I do that?</p>
  
  <hr>
  
  <p>OK, so this is how I've implemented it:</p>
  
  <pre><code>function getRowById ( $result, $id )
  {
      while ( $row = mysql_fetch_array( $result ) ) {
          if ( $row['id'] == $id ) {
              mysql_data_seek( $result, 0 );
              return $row;
          }
      }
  }
  </code></pre>