title: Create an HTML table like this one
body: <p>i posted a question a while ago and i got my answer but now i kind of want a followup to this problem so i have a table like the one in the picture but i want to add total to each row or in fact a group how can i do that.
  This is the php code to create this table how to edit it to add the total.</p>
  
  <pre><code>$sql = mysql_query(
    "SELECT s.login AS 'from', r.login AS 'to',COUNT(*) as'message_count'
    FROM messages AS m,groups AS s,groups AS r
    WHERE m.Group_ID = s.id
    AND m.To_Group_ID = r.id
    AND m.Simulation_ID = ".$_SESSION['sim_id']."
    AND s.kind_of_user NOT IN (3,1)
    AND r.kind_of_user NOT IN (3,1)
    AND m.Group_ID IN
      (SELECT Group_ID FROM simulationgroups
         WHERE Simulation_ID = ".$_SESSION['sim_id'].")
    AND m.To_Group_ID IN
      (SELECT Group_ID FROM simulationgroups
         WHERE Simulation_ID = ".$_SESSION['sim_id'].")
    GROUP BY m.Group_ID, m.To_Group_ID
    ORDER BY s.id DESC"
    ) or die (mysql_error());
  
  $data = array();
  while($row = mysql_fetch_assoc($sql)) 
  { 
     $data[$row['to']][$row['from']] += $row['message_count'];   
  }
  
   // Print headers
  $columns = array_keys($data);
  echo "&lt;table class='msg_dynamics' cellspacing=0
    cellpadding=0 border=1px&gt;&lt;tr&gt;&lt;th&gt;&lt;&lt;&lt;/th&gt;";
  
  foreach($columns as $_column) 
  {
    echo "&lt;th width='10%'&gt;{$_column}&lt;/th&gt;";
  }
  
  echo "&lt;th width='10%'&gt;total&lt;/th&gt;";
  echo "&lt;/tr&gt;";
  
  // Print data
  foreach($data as $_row_name =&gt; $_row_data) 
  {
    // Add the dash (-) for empty cells
    $_row_data[$_row_name] = '-';
  
    echo "&lt;tr&gt;&lt;td width='10%'&gt;{$_row_name}";
    foreach($columns as $_col_name) 
    {
      echo "&lt;td&gt;{$_row_data[$_col_name]}&lt;/td&gt;";
    }
  
    echo "&lt;/td&gt;&lt;/tr&gt;";
  }
  
  echo "&lt;tr&gt;&lt;td&gt;&lt;b&gt;total&lt;/b&gt;&lt;/td&gt;";
  </code></pre>
  
  <p>";</p>
  
  <p><a href="https://i.stack.imgur.com/Ln5OF.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ln5OF.jpg" alt="Screenshot"></a>
  </p>