title: PHP MySQL fetch result and display
body: <p>Trying to learn some more PHP and MySQL here now, and I'm having problems understanding how this works. I do know other languages, so I'm hoping I will understand PHP much better if I just can get some help with this example:</p>
  
  <p>I have a table called files. This contains 3 rows (3 files), where I've defined fileID, thumbURL, fullRUL, and stuff like that.</p>
  
  <p>on my webpage I want to fetch this whole list of items/files, and do a for loop to display them all.</p>
  
  <p>This is my PHP code, which of course repeats itself 3 times but it displays the same information, because it only uses the same row:</p>
  
  <pre><code>    &lt;div id="contentWrapper"&gt;
      &lt;?php
      for($i = 0; $i &lt; $numItems; $i++){
          echo "&lt;div id='contentItem'&gt;";
          echo "&lt;a href='".$row['fullURL']."' title='".$row['description']."'&gt;&lt;img src='". $row['thumbURL']."' width='200px' height='150px' /&gt;&lt;/a&gt;";
          echo "&lt;/div&gt;";
      }
      ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This is the code where I get the data from the database:</p>
  
  <pre><code>    &lt;?php
  $db = mysql_connect("localhost", "xxxxx", "xxxxx");
  mysql_select_db("login",$db) or die("Kan ikke koble til databasen");
  
  $filesSQL = mysql_query("SELECT * FROM files");
  $numItems = mysql_num_rows($filesSQL);
  
  $sql="SELECT * FROM `files` WHERE fileID=1";
  $result=mysql_query($sql);
  
  if (false === $result) {
  echo mysql_error();
  }
  
  $row=mysql_fetch_array($result, MYSQL_BOTH);
  ?&gt;
  </code></pre>
  
  <p>The current example here does only fetch the firsst row and stores that in an array, so thats why I get the same values on all 3 items.</p>
  
  <p>But I've tried using $filesSQL[$i]['thumbURL'] and other similar methodes, but I cant get it to work.</p>
  
  <p>I guess this is a very basic question, so I'm hoping for an answer that will help me understand how to work with databases, arrays and displaying it.</p>
  
  <hr>
  
  <p>I can easily do this in Actionscript3 or other languages, but not in php! =S</p>
  
  <p>Thanks! =D</p>