paulp75
asked on
adding the values of multiple records matching a criteria
<?
require_once 'dbconnect.php';
$result = mysql_query("select * from stats order by count desc");
while($r=mysql_fetch_array ($result))
{
$count=$r["count"];
$refdomain=$r["refdomain"] ;
echo "
<table><tr><td><a class='mnu1'>$refdomain</t d><td class='infobox2'><a class='mnu1'>$count</td></ tr></table >";
}
?>
ok what this will bring up is stats like this.
domain1 54
domain1 38
domain2 25
domain3 22
21
domain4 20
domain4 19
the blank ones are for no referrers.
what i'd like to do is this
i'd like to add all of the records of domain1,2,etc
and order by the total per domain
and preferably have the blank records outputting as "bookmark"
so the output would look like this
domain1.com 92
domain4.com 39
domain2.com 25
domain3.com 22
bookmark 21
how would i go about that?
thanks
require_once 'dbconnect.php';
$result = mysql_query("select * from stats order by count desc");
while($r=mysql_fetch_array
{
$count=$r["count"];
$refdomain=$r["refdomain"]
echo "
<table><tr><td><a class='mnu1'>$refdomain</t
}
?>
ok what this will bring up is stats like this.
domain1 54
domain1 38
domain2 25
domain3 22
21
domain4 20
domain4 19
the blank ones are for no referrers.
what i'd like to do is this
i'd like to add all of the records of domain1,2,etc
and order by the total per domain
and preferably have the blank records outputting as "bookmark"
so the output would look like this
domain1.com 92
domain4.com 39
domain2.com 25
domain3.com 22
bookmark 21
how would i go about that?
thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<?php
require_once 'dbconnect.php';
$result = mysql_query("select sum(count) as sumcount, refdomain from stats group by refdomain order by sumcount desc");
while($r=mysql_fetch_array ($result))
{
$count = $r["sumcount"];
$refdomain = (empty($r["refdomain"])) ? "bookmark" : $r["refdomain"];
echo "
<table><tr><td><a class='mnu1'>$refdomain</t d><td class='infobox2'><a class='mnu1'>$count</td></ tr></table >";
}
?>
require_once 'dbconnect.php';
$result = mysql_query("select sum(count) as sumcount, refdomain from stats group by refdomain order by sumcount desc");
while($r=mysql_fetch_array
{
$count = $r["sumcount"];
$refdomain = (empty($r["refdomain"])) ? "bookmark" : $r["refdomain"];
echo "
<table><tr><td><a class='mnu1'>$refdomain</t
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks for the answers there.
the last one worked awesome.
the other two were good, but didnt include the bookmark thingy.
thanks for all your help.
the last one worked awesome.
the other two were good, but didnt include the bookmark thingy.
thanks for all your help.
$result = mysql_query("select refdomain,sum(count) as count from stats group by refdomain order by count desc");