title: Retrieving mysql table data that is stored within a php variable array
body: <p>My connection to my database was successful. I now have all of the data from a table stored as an array in a php variable named $data. I am trying to extract three rows from this variable and display them with html.</p>
  
  <p>Here is what my code looks like (with the exception of the connection info being removed):</p>
  
  <pre><code>    &lt;?php 
      $data = mysql_query("SELECT * FROM specs")
      or die(mysql_error());
      while ($row = mysql_fetch_assoc($data)) {
      $rows[] = $row;
      ?&gt;
  </code></pre>
  
  <p>I know that I can pull individual data from this variable and insert it into html successfully by entering code like this (for example):</p>
  
  <pre><code>    &lt;table cellpadding="0" cellspacing="0" border="0"&gt;
        &lt;tr&gt;
          &lt;td&gt;Model: &lt;?php echo $row['name'];?&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
  </code></pre>
  
  <p>But my problem is that I want to display three separate rows of data from the database as three individual columns in a html table. (Hope that makes sense)</p>
  
  <p>I've looked into how to do this with foreach and while but am not quite sure where I'm going wrong.</p>
  
  <p>I'm hoping someone might be able to shed some light on this as I have read about foreach loops, while, and am still stuck! I'm also hearing that mysql_query is deprecated but ruled out not using this since our webserver is still using an old version of php and mysql and is not planning to update anytime soon.</p>
  
  <p>Sorry if I'm not all here in my post - it's late and I'm tired. Thanks for your help in advance! I'll keep an eye on this in case anyone has questions.</p>