php and html table logic
<p>So I have an table that has values from database:</p>

<pre><code>$result=mysql_query("SELECT * FROM database WHERE date = '$period'") or die (mysql_error());
while ($row_result = mysql_fetch_array($result) {
  $article = $row_result['article'];
  ...
  //It shows something like this:

id  |  article |  some more data |
4   |  1234    |  data           |
8   |  654     |  data           |
9   |  654     |  data           |
</code></pre>

<p>Each row is shown, but now what I would like to do is show another row after each article that sums up some values, but if the article numbers are the same then show one row after for example those two. I don't now how many article numbers are the same, but if they are shown after one another in a table and they have the same value then I would like to show a row after them.</p>

<p>First I did something like this:</p>

<pre><code> $article2 = "";
 if ($article2 != $article) {
    &lt;td&gt;...&lt;/td&gt;
       .....  
 }
 $article2 = $article;
</code></pre>

<p>But this is useful for unique article, it shows an extra row after an article, but if I have like 5 rows with the same article it shows the extra row after the first article. Like so:</p>

<pre><code>    id  |  article |  some more data |
    4   |  1234    |  data           |
extra   |  1234    |  sum data       |
    8   |  654     |  data           |
extra   |  654     |  sum data       |
    9   |  654     |  data           |
</code></pre>

<p>I need help with some kind of logic that understands that the extra row is only shown after each different article number. I hope you guys understand what I am trying to do :) I would appreciate some help.</p>
