title: Mysql fetch all rows and echo as json
body: <p>I've got a database with 5 columns and multiple rows. I want to fetch the first 3 rows and echo them as an array. So far I can only get the first row (I'm new to PHP and mysql). Here's my PHP so far:</p>
  
  <pre><code>//==== FETCH DATA
  $result = mysql_query("SELECT * FROM $tableName");
  $array = mysql_fetch_row($result);    
  
  //==== ECHO AS JSON
  echo json_encode($array);
  </code></pre>
  
  <p>Help would be much appreciated.</p>