I have table i wish to count how many times a value appears in all column the table structure

id Subject1 Subject1score subject1grade Subject2 Subject2score subject2grade
1  English    100               A       Mathematics   100      C


$subject3grade='B'; $a=array("$subject1grade","$subject2grade","$subject3grade");


Array ( [A] => 2 [B] => 1 )

I NEED THE CODE TO DISPLAY You made 2A(s), 1B(s)

I want to count how many A's and C's

Recommended Answers

All 3 Replies

The way I would do this is to make the tables more general. You have a table set up for a specific number of courses. If you need to add or remove courses you have to alter the table. Instead, you should have a table that maps courses to a course ID. Then you can have a table that tracks any number of courses. Adding a new course is simply a matter of adding a record to the mapping table, then adding one or more records to the tracking table. That gives you the ability to query the tracking table for how many times any value appears for any course without having to do the query for every course column.

Look up "Database Normalization" and then apply what you learned.

Great tip, but there is no C in the code at all? Why?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.