Link to home
Start Free TrialLog in
Avatar of paulp75
paulp75Flag for Australia

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</td><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
Avatar of Batalf
Batalf
Flag of United States of America image

Maybe you could just change the query:


$result = mysql_query("select refdomain,sum(count) as count from stats group by refdomain order by count desc");

SOLUTION
Avatar of Batalf
Batalf
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<?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</td><td class='infobox2'><a class='mnu1'>$count</td></tr></table>";
 }
?>
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of paulp75

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.