Reputation: 55
I made a school voting with 10 questions. There you can check one teacher for every question (in total there are 80 teachers). When someone has voted for all questions, a new row in my mysql table will be inserted.
My Mysql Table has 10 fields (for every question one(q1,q2,q3)). The name of the teacher for one question will be an integer (every teachers has an id from 1 - 82).
That is what the table looks like
Now I want to find out for which teacher is how often voted for each question. That should do a php script. It should echo something like this:
The result should be something like this
How to do this?
Upvotes: 0
Views: 45
Reputation: 5509
This query will give number of times each teacher is voted for question q1.
$sql = "SELECT q1, COUNT(*) AS votes FROM table1 GROUP BY q1 ORDER BY votes";
$ref = $result->query($sql);
while($row = mysqli_fetch_assoc($ref))
{
echo "$row[votes] times $row[q1]</br>";
}
You can do the same for other questions, just by changing the column name for question number
Upvotes: 1