Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8347171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:16:45+00:00 2026-06-09T07:16:45+00:00

Im currently creating a voting module for my website, and i have to check

  • 0

Im currently creating a voting module for my website, and i have to check if the user voted already, it would just select * from the vote logs, my script inserts a new record for each vote, so say you vote on site 1 its a different record, then say if you voted for site 2.

The columns are site, and the username. I wan’t to be able to check if they voted on all sites based on their username in one php mysql query SELECT * FROM TABLE_NAME

And then sort through the information that way, but i can’t wrap my head around it….

Any help’s appreciated as always!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:16:47+00:00Added an answer on June 9, 2026 at 7:16 am

    Here is how I would set it up:

    Users table:

    CREATE TABLE users(    
        userid    INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
        username  VARCHAR(50) NOT NULL,
        UNIQUE INDEX(username)
    );
    

    Sites table:

    CREATE TABLE sites(    
        siteid    INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
        sitename  VARCHAR(50) NOT NULL,
        UNIQUE INDEX(sitename)
    );
    

    Votes table:

    CREATE TABLE votes(    
        timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
        userid INT UNSIGNED NOT NULL,
        siteid INT UNSIGNED NOT NULL,
        UNIQUE INDEX(userid,siteid)
    );
    

    When a user casts a vote:

    INSERT INTO votes(userid,siteid) VALUES ("$userid","$siteid")
    

    To see what sites a user has voted on:

    SELECT sites.sitename FROM sites
    INNER JOIN votes ON sites.siteid=votes.voteid
    WHERE votes.userid="$userid"
    

    To see what sites a user has NOT voted on (if no rows are returned, then the user has voted on every site):

    SELECT sitename FROM sites
    WHERE siteid NOT IN (
        SELECT siteid FROM votes WHERE userid="$userid"
    )
    

    I like this solution, because then you can display which sites the user has not voted on.

    A couple final notes: (1) Never, EVER use “SELECT * FROM table” in a production setting; this is terrible performance. Always select the only the rows you need. And (2) be sure to quote the user input on your queries to avoid SQL injection attacks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently creating a script to synchronize users from our company's website onto
I am currently creating an e-commerce site using C# ASP.NET MVC and have just
Im currently creating my own forum for my website and i have read plenty
I am currently creating a website and have some javascript that works in all
im currently creating a graph for an app, using coreplot and have a problem
I am currently creating a Perl module for in house use. I used ExtUtils::ModuleMaker
I am currently creating a console application which is reading from a folder which
I am currently creating an application that has a user, the user can follow
I'm currently creating a subscription membership for my website. I'm storing the date their
I'm currently creating my first Chrome extension, so far so good. It's just a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.