Fill This Form To Receive Instant Help
Homework answers / question archive / Create the database/Setup database tables Identify a Primary Key Store the questions results each time a response is submitted
Create the database/Setup database tables
Identify a Primary Key
Store the questions results each time a response is submitted.
Use INSERT statements to populate the table
Issue SELECT SQL statement(s) that request all the possible answers for the poll.
Use a WHILE loop to extract info from the MySQL result set
Use the MySQL function COUNT() to count the number of records in the table
Display the number of votes the chosen answer received.
I used 3 tables. 1 table to store the possible colors, 1 table to store the possible seasons, and another to store the votes. There are an additional two attributes in that table, the sex and the marital status.
I chose to store each vote that comes in. This way we have the maximum possible ability to look at the data afterwards. If you just recorded the count of each, it doesn't tell you any relationship between color and sex for example.
The primary key for the votes table would be the the "id". There is no other possible primary key. If we took all the fields except for the "id" to be the primary (composite) key, that would not be good enough, as some people might vote for the same combination of responses, therefore that is not a unique key. So "id" is the only possible primary key here.
Please see the attached mysql initialization file as well as the php code that I have implemented and tested. It does not count the votes but it does display all the results. It should be easy to do all sorts of statistics or whatever you want. All the framework is there in the code.
By the way, in PHP, the mysql_numrows($result); does the COUNT for you.