title: getting results of SQL query
body: <p>I've seen there there are numerous ways to put the results of a SQL query into usable format (that is, variables).</p>
  
  <p>If I have a targeted SQL query that I know will be returning a set of expected values,  lets say querying a customer number to pull data, city, state, first and last name, etc..</p>
  
  <p>Code example follows:</p>
  
  <pre><code>$example = '50';
  $result = mysql_query("SELECT * FROM customers WHERE customer_ID = '$example'",$db);
  while ($row = mysql_fetch_assoc($result)) {
    foreach ($row as $col =&gt; $val) {
      if ($col == 'firstname') {
        $customerfirstname = $val;
      }
    }
  }
  </code></pre>
  
  <p>or another way:</p>
  
  <pre><code>$result = mysql_query("SELECT * FROM customers WHERE customer_ID = '$example'",$db);
  $myResultArray = array();
  
  while ($row = mysql_fetch_assoc($result))
    $myResultArray = $row;
  
    foreach ($myResultArray as $val) {
      $customerfirstname = $val['firstname'];
    }
  </code></pre>
  
  <p>That's just two that I could think of.</p>
  
  <p>Is one of the above methods preferable over the other?  If so, why?</p>
  
  <p>Is there an alternate method that is even more efficient than either of these?</p>