Here is my code:
$query = "SELECT TGTDESC,StatusYYMM,Sum(TGTNUM) AS pestCount
FROM pdstg
WHERE PTYID = '$PTYID'
AND PRYSID = '$PRYSID'
GROUP BY StatusYYMM,TGTDESC
ORDER BY StatusYYMM DESC";
$result = mysql_query($query, $link) or die(mysql_error());
$num_rows = mysql_num_rows($result);
while ($row = mysql_fetch_assoc($result))
{
$StatusYYMM = $row['StatusYYMM'];
$TGTDESC = $row['TGTDESC'];
$pestCount = $row['pestCount'];
echo "<b>$StatusYYMM</b> ";
echo "$TGTDESC - $pestCount<br>";
}
Result:
2006 01 Cigarette Beetles - 1
2006 01 General Spiders - 1
2006 01 House Flies - 3
2006 01 Moths, Species Unknown - 19
2006 01 Nighttime Beetles - 12
2005 12 American Roaches - 1
2005 12 Crickets - 2
2005 12 General Spiders - 2
2005 12 German Roaches - 1
2005 12 House Flies - 6
2005 12 Indian Meal Moths - 10
2005 12 Nighttime Beetles - 4
2005 12 Nighttime Moths - 115
2005 11 American Roaches - 2
2005 11 Crickets - 124
2005 11 Earwigs - 1
2005 11 General Spiders - 4
2005 11 German Roaches - 1
2005 11 House Flies - 15
2005 11 Indian Meal Moths - 21
2005 11 Mice - 1
2005 11 Moths, Species Unknown - 48
2005 11 Nighttime Beetles - 62
2005 11 Other Nighttime Flying Insects - 12
2005 10 American Roaches - 1
2005 10 Bees - 2
2005 10 Carpenter Ants - 22
2005 10 Crickets - 717
2005 10 Drugstore Beetles - 1
2005 10 General Spiders - 5
2005 10 German Roaches - 1
2005 10 House Flies - 12
2005 10 Indian Meal Moths - 44
2005 10 Mice - 2
2005 10 Moths, Species Unknown - 47
2005 10 Nighttime Beetles - 33
2005 10 Other Filth Flies - 15
2005 10 Other Nighttime Flying Insects - 2
2005 10 Rats - 1
2005 09 American Roaches - 2
2005 09 Carpenter Ants - 3
2005 09 Crickets - 689
2005 09 General Spiders - 3
2005 09 German Roaches - 1
2005 09 House Flies - 41
2005 09 Indian Meal Moths - 47
2005 09 Moths, Species Unknown - 46
2005 09 Other Nighttime Flying Insects - 15
2005 09 Stored Product Pest - 35
2005 08 American Roaches - 2
2005 08 Bees - 35
2005 08 Crickets - 1260
2005 08 General Spiders - 10
2005 08 German Roaches - 9
2005 08 House Flies - 25
2005 08 Mice - 6
2005 08 Moths, Species Unknown - 61
2005 07 American Roaches - 4
2005 07 Crickets - 199
2005 07 General Spiders - 7
2005 07 German Roaches - 66
2005 07 House Flies - 43
2005 07 Mice - 1
2005 07 Moths, Species Unknown - 5
2005 07 Nighttime Beetles - 17
2005 07 Nighttime Moths - 30
2005 07 Other Nighttime Flying Insects - 200
2005 06 Fruit Flies - 20
2005 06 Fungus Gnats - 22
2005 06 Moths, Species Unknown - 19
2005 05 Crickets - 7
etc....
how do i group first by StatusYYMM and then group by TGTDESC with only one SELECT statement? i assume that an array(s) is called for but i'm not sure how to do it. thanks in advance.