Jump to content

Creating a poll


Love2c0de

Recommended Posts

Hi guys, I am creating a website which allows the users to upload their own gaming demo recordings.

 

I have 2 sidebars (left and right) and a main content area. In the right sidebar, I'd like to add some general information from the database, such as latest 5 members, latest 5 demos uploaded etc. I want to put a poll under that information asking my users about which game they would like to see added to the website.

 

I'm really not sure on how to achieve this because I can't just process it like a normal form then send them back because they will be able to re-submit the poll form.

 

How do I disable/hide the poll form depending on whether that certain user has already voted on the poll?

 

I know it's something to do with checking the session when processing the form.

 

Could one way be to add another field in my members table, let's say 'poll' and populate it with a value of FALSE. Then when processing the poll form data, use their username to identify the correct row and then change the value from FALSE to TRUE.

 

Then before displaying the poll, do some checking to see if that user's column is set to TRUE and if it is then I hide the form, if it is still set to FALSE then display it?

 

Looking at it, I think that could work maybe but I wanted to know if there is a more efficient way. I want the least amount of queries as posible and I'm terrible with joins.

 

I haven't wrote any code so far so I can't provide any code unless you want to see my setup.

 

Thank you in advance for any help.

 

Kind regards,

 

L2c.

Edited by Love2c0de
Link to comment
Share on other sites

I think you are making it more difficult than it needs to be. Assuming you may want to conduct different polls you will want three tables. One table will be for the Poll question. Another will be for the poll answers. Each record will be a different answer and will have a foreign key reference back to the poll record. When creating a new poll the data will be added to both of those tables before the poll can be used. Then when a poll is ready you simply add a record to the third table (poll_results) when a user answers the poll. But, here is the trick: the query should be an INSERT ON DUPLICATE KEY UPDATE query. Then a user can answer the poll again, but it will only update their previous answer instead of creating a new result. To do this you need to make the COMBINATION of the poll_id and the user_id a unique key.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.