Such is life ! Your DB is structured wrongly. What you should have is Rows as opposed to Columns, so the count will be a simple GROUP BY Query. Now you have complicated the process. Although what you wish to do is not impossible, it is still a hassle.
Try restructuring your table ! We might be able to give you better guidance.