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

  • Home
  • SEARCH
  • 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 374917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:27:07+00:00 2026-05-12T14:27:07+00:00

I have a simple contest sign-up web form. Each contestant can check a box

  • 0

I have a simple contest sign-up web form. Each contestant can check a box to be eligible to win one of 20 prizes. Upon submitting a form, a row is created in the “contestants” table. For each prize they have checked, a row in the “entries” table is created.

I am trying to make a “results” page that lists all prize names, and below each prize name all of the contestants who want to be eligible to win that prize. Prizes for which no contestants have signed up will have no contestants listed below their name.

How do I write an efficient MySQL query to easily produce such a page (using PHP)?

Tables

contestants

  • id
  • name
  • email
  • address
  • city
  • state

entries

  • id
  • contestant_id
  • prize_id

prizes

  • id
  • name
  • description
  • 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-05-12T14:27:07+00:00Added an answer on May 12, 2026 at 2:27 pm
    SELECT p.name AS prize, c.name AS contestant FROM contestants c
    INNER JOIN entries e ON c.id = e.contestant_id
    INNER JOIN prizes p ON e.prize_id = p.id
    ORDER BY p.id
    

    It will give you the result:

    prize 1 | contestant 1.1
    prize 1 | contestant 1.2
    ...
    prize 1 | contestant 1.n
    prize 2 | contestant 2.1
    prize 2 | contestant 2.2
    ...
    prize 2 | contestant 2.n
    ....
    prize m | contestant m.n
    

    If you want to have the list like this:

    prize 1
        contestant 1.1
        contestant 1.2
        ...
        contestant 1.n  
    prize 2
        contestant 2.1
        contestant 2.2
        ...
        contestant 2.n
    

    You have to format the result in PHP.

    It can be something like this:

    $old_prize = '';
    
    $result = mysql_query(<above query>);
    
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    
        if($old_prize != $row["prize"]) {
            $old_prize = $row["prize"];
            echo "Prize: ".$row["prize"].'<br />'; 
        }
    
        echo $row["contestant"].'<br />;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a very simple ASP.NET web application comprising mostly static content and a
I have simple win service, that executes few tasks periodically. How should I pass
I have a simple content edit form (Zend_Form) that I populate() with an array
I have a java web application running on tomcat, and will use single sign
Say I have a simple form like this: <html> <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8
I have a simple sign in tablelayout, but the contents inside are stretching too
I'm using jQuery and have managed to paste together a simple accordion which can
I have a simple form in my MVC3 site that allows users to create
I have a simple markup .content{ -webkit-column-width: 100px; width : 200px; height: 100px; }
I have written simple code to get content from xml file to php. $xml

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.