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 7930077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:18:06+00:00 2026-06-03T20:18:06+00:00

I have tables: events —–+——————-+ | id | eventName | —–+——————-+ | 1 |

  • 0

I have tables:

events

    -----+-------------------+
    | id | eventName         |
    -----+-------------------+
    | 1  | Bowling           |
    | 2  | Quiz              |
    | 3  | Darts             |
    | 4  | Pool              |
    | 5  | Treasure Hunt     |
    | 6  | Snooker           |
    -----+-------------------+

competitors

    ------+------------------+
    | id  | competitorName   |
    ------+------------------+
    | 1   | Microsoft        |
    | 2   | BBC              |
    | 3   | Facebook         |
    ------+------------------+

results

    ------+---------------+---------+-------------+
    | id  | competitorId  | eventId |  eventScore |
    ------+---------------+---------+-------------+
    | 1   | 1             |  1      |   12        |
    | 2   | 1             |  2      |   11        |
    | 3   | 1             |  3      |   23        |
    | 4   | 2             |  1      |   66        |
    | 5   | 2             |  2      |   12        |
    | 6   | 2             |  3      |   11        |
    | 7   | 2             |  4      |   23        |
    | 8   | 2             |  5      |   66        |
    | 3   | 2             |  6      |   23        |
    | 4   | 3             |  1      |   66        |
    | 5   | 3             |  2      |   12        |
    | 6   | 3             |  3      |   11        |
    | 7   | 3             |  4      |   23        |
    | 8   | 3             |  6      |   66        |
    ------+---------------+---------+-------------+

From which I want to achieve output like this:

    --------------+---------+---------+--------+------+--------------+----------
    | competitor  | Bowling | Quiz    |  Darts |Pool  |Treasure Hunt | Snooker | 
    --------------+---------+---------+--------+------+--------------+----------
    | Microsoft   | 12      |  11     |   23   |  0   | 0            | 0       |
    | BBC         | 66      |  12     |   11   |  23  | 66           | 23      |
    | Facebook    | 66      |  12     |   11   |  23  | 0            | 66      |
    --------------+---------+---------+--------+------+--------------+----------

I have tried all sorts of joins and nested php but I just can’t crack it. I’m not even sure if it’s possible. My SQL knowledge is not great, I’ve tried some tutorials but they don’t cover this kind of query.

  • 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-03T20:18:07+00:00Added an answer on June 3, 2026 at 8:18 pm

    You can create your query by php like this

    <?php
    $events = array('Assume this is array of events table with id,eventName as key');
    
    $column = array();
    foreach($events as $event)
    {
         $column[] = 'SUM(IF(results.eventId = '.$event['id'].', results.eventScore, 0)) AS '.$event['eventName'];
    }
    
    $sql = 'SELECT   competitors.competitorName AS competitor,';
    $sql .= implode(',',$column);
    $sql .= ' FROM competitors';
    $sql .= ' LEFT JOIN results ON results.competitorId = competitors.id';
    $sql .= ' GROUP BY competitors.id';
    //Put $sql into mysql_query then
    

    Then, to get row dynamically

    while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
        foreach($row as $k=>$v) 
        {
             //Here you get Column Name as $k  and data value as $v
        }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have 2 tables: Events (idEvent, eventName) and Registrations(idRegistration, idEvent, idPerson) People register
I have 2 tables: dbo.Events EventID EventName Location 1 Birthday Party 2 2 Wedding
I have two tables: events and events_actions events columns: event_id user_id event_name events_actions columns:
I have 2 tables events and events_visibility events table and the column id -
I have two tables, events and photos, which relate together via the 'Event_ID' column.
I have 2 tables. In one table I add events, ID are auto-increment. The
I have two msyql tables, Badges and Events. I use a join to find
Well, I have two tables: events : id , title , description trip_events :
I'm having a problem with LINQ. I have 2 tables (Parent-child relation) Table1: Events
I have events , events_styles , events_formats tables (an event can have many styles

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.