title: Display MySQL Query Results in Twig Template
body: <p>I'm implementing my first Twig project.  I have a MySQL database. It includes a table where each record is a document. There are Title, Number, and Description fields.</p>
  
  <p>Without Twig, it was pretty straightforward to query all the results and output them to a table.  However, I'm having some difficulty getting the query to Twig.  It seems like a basic task, but I haven't found any similar examples in the Twig documentation or by searching around.</p>
  
  <p>Twig templates look a lot like Django/Jinja templates, which I'm more familiar with.  My template:</p>
  
  <pre><code>{% block Content %}
  
  &lt;table border='1' width=100%&gt;
      {% for i in queryResult %}
      &lt;tr&gt;
          &lt;td&gt; {{i.Title}} &lt;/td&gt;
      &lt;/tr&gt;
      {% endfor %}
  &lt;/table&gt;
  {% endblock %}
  </code></pre>
  
  <p>The PHP for this view looks like this:</p>
  
  <pre><code>$connection=mysql_connect (credentials) or die ('Cannot connect to database:' . mysql_error());
      $mydb=mysql_select_db(database);
  
  $sql = query;
  
  $query = mysql_query($sql);
  
  $result = mysql_fetch_assoc($query);
  
  echo $twig -&gt; render('all_reports.html', array('queryResult'=&gt; $result));
  </code></pre>
  
  <p>Which seems right. The script should execute a SQL query, return the resultset as an array, and then send the result to the template.  The template should iterate over all the items in the array (one item for each row) and display them in a table.</p>
  
  <p>What actually happens is that a three rows are rendered, all blank.  My interpretation is that the template sees three items in the array (one for each field) instead of an item for each record in the query result.  They are blank because each field doesn't have a Title field.  But I'm at a loss as to what would fix this.</p>