FromHollandWithLove
Junior Member
Hi, i am writing my own webstats script and have encountered the following problem.
I extract referring domains from the stats database with the following query:
Subsequently, i write a table containing the domains ($ref_domein) on the left and the amount of hits per domain ($aantal1) on the right. Like this:
An example can be viewed at the bottom of this page: http://www.odessa.nl/internetdelen/stats.php
Now, i want to calculate the percentages of the total amount of hits instead of the amounts. The problem is, that i already need $total at the moment i start calculating the first percentage, while $total now becomes available at the end of the table. Can you help me out?
I extract referring domains from the stats database with the following query:
$ref_query="SELECT Count(*) as aantal1, ref_domein FROM pageviews
WHERE ref_domein != 'odessa.nl' AND ref_domein != 'none'
Group By ref_domein order by aantal1 desc";
Subsequently, i write a table containing the domains ($ref_domein) on the left and the amount of hits per domain ($aantal1) on the right. Like this:
echo "<table bgcolor='#000000' cellpadding='2' cellspacing='1' border='0'>";
echo "<tr><td colspan='3' bgcolor='#CEF4FD'><font color='#000066'>Ref domains</font></td></tr>";
while($q=mysql_fetch_array($result_ref))
{
$aantal1=$q["aantal1"];
$totaal += $aantal1;
$ref_domein=$q["ref_domein"];
echo "<tr bgcolor='#f5f5f5'><td>$ref_domein</td><td>$aantal1<td/></tr>";
}
echo"<tr><td colspan='2' align='right' bgcolor='#ffffff'>$totaal</td></tr>";
echo "</table>";
An example can be viewed at the bottom of this page: http://www.odessa.nl/internetdelen/stats.php
Now, i want to calculate the percentages of the total amount of hits instead of the amounts. The problem is, that i already need $total at the moment i start calculating the first percentage, while $total now becomes available at the end of the table. Can you help me out?