Hi and thanks to all of you for your help, especially Hand.
This example worked nicely and I am now trying to modify it as follows:
$select = "select Year, count(*) as count, Response, count(*) as count2 from bdhsa group by Year, Response";
$result1 = mysql_query ($select);
////////////////////////////////////////////////////////////////
// main code
////////////////////////////////////////////////////////////////
// Display table by row using array and format into html table
while ($row = mysql_fetch_array ($result1) ) {
// limit data output to responses with yes for testing
if ($row[Response] = "yes") {
print "<td>$row[Year] </td>";
print "<td>$row[count] </td>";
print "<td>$row[count2]</td>";
}
}
////////////////////////////////////////////////////////////////
The problem now is that I should be displaying the year once per line
with a total number of records per year and the total of "yes" responses.
I have tried to use a second WHILE statement as an internal loop as well as
a FOR and IF statements but can't seem to get it right.
The results I received shown here display year twice, except when I remove
the "RESPONSE" in the group by, and also the totals should not be equal:
YEAR TOTAL_CNT YES_CNT
1950 4 4
1950 1 1
1951 1 1
1951 2 2
1952 1 1
1952 2 2
1952 1 1
1953 6 6
1953 4 4
1954 3 3
1955 8 8
1955 1 1
1955 2 2
The output should have been this for example:
YEAR TOTAL_CNT YES_CNT
1950 10 4
1951 12 1
1952 21 1
1953 16 6
1954 30 3
1955 28 8
I am still trying to use arrays as best as possible.
Thanks again,
Peter