I am running a survey where I have 5 questions. Each question has an answer of a, b, or c. I am storing the results in a mysql db. I need to output the results and getting a 'count' of how many times a, b or c occurs in each question. I have tried a few things like:
$sql2="SELECT * FROM dad_contest";
$result2 = @($sql2, $connection) or die(mysql_error());
$num_rows=mysql_num_rows($result2);
if (mysql_num_rows($result2) >0 ) {
while ($row2 = mysql_fetch_array($result2)) {
//q1
if($row2[q1] == "a") {
for ($a=0; $a <= $num_rows; $a++) {
$q1a = $a;
}
}
elseif ($row2[q1] == "b") {
for ($b=0; $b <= $num_rows; $b++) {
$q1b = $b;
}
}
else {
for ($c=0; $c <= $num_rows; $c++) {
$q1c = $c;
}
}
This could be my lack of understanding of for loops like a previous post I just did with a similar issue. This needs to be run for all 5 questions (q1, q2, q3, q4, q5). Any ideas and/or help is always appreciated. The solution may be more complicated than my experience.
Thanks in advance for any advice.
Matt