title: Using arrays to populate a table
body: <p>I am trying to count the number of images submitted to photo competitions. I am using an array (called $frequencies) to store my values generated from my query. I can create a table with both the competition name and count of entries, but cannot see how I can include the id associated with each of the competitions. In short, I'd like to have the id, competition name, and count - I can get all three of these but not so that the id can be used in a link to direct users to the specific competition).</p>
  <p>I get this (everything works as it should, but no id):</p>
  <p><a href="https://i.stack.imgur.com/F2B55.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/F2B55.png" alt="enter image description here" /></a></p>
  <p>...but want this (I cannot think how to get id into the table):</p>
  <p><a href="https://i.stack.imgur.com/mLFqt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mLFqt.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/Xocyq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Xocyq.png" alt="enter image description here" /></a></p>
  <p>See my query and array below.</p>
  <pre><code>&lt;?php
    $con = mysqli_connect( DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE );
    if ( mysqli_connect_errno() ) {
      echo &quot;Failed to connect to MySQL: &quot; . mysqli_connect_error( $con );
    }
    $frequencies = array();
    $cnt_result = &quot;SELECT entered_images.id AS compID,
  competitions.name AS compName, 
  COUNT(entered_images.id) AS Freq 
  FROM entered_images 
  INNER JOIN competitions 
  ON competitions.id = entered_images.id 
  GROUP BY competitions.name&quot;;
    $cnt_Recordset1 = mysqli_query( $con, $cnt_result )or die( mysqli_error( $con ) );
    $row_Recordset1 = mysqli_num_rows( $cnt_Recordset1 );
    if ( $cnt_Recordset1 === false ) {
      trigger_error( mysqli_error( $GLOBALS[ 'con' ] ) );
    }
    while ( $row = mysqli_fetch_row( $cnt_Recordset1 ) ) {
      $frequencies[$row[1]] = $row[2];
    }
    ?&gt;
  </code></pre>
  <p>This works as required. Here is how I get the values into my table:</p>
  <pre><code>&lt;table width=&quot;95%&quot; border=&quot;1&quot; align=&quot;center&quot;&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td align=&quot;center&quot; bgcolor=&quot;#F8F2C3&quot;&gt;&lt;strong&gt;Competition Name&lt;/strong&gt;&lt;/td&gt;
        &lt;td align=&quot;center&quot; bgcolor=&quot;#F8F2C3&quot;&gt;&lt;strong&gt;Count&lt;/strong&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;?php foreach ($frequencies as $name =&gt; $count) {?&gt;
      &lt;tr&gt;
        &lt;td&gt;&lt;?php echo $name?&gt;&lt;/td&gt;
        &lt;td align=&quot;center&quot;&gt;&lt;?php echo $count; ?&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;?php
      }
      ?&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>