Site icon Sock It Forward

PHP SQL grouping all columns with same starttime

PHP SQL grouping all columns with same starttime

so i am having trouble coding the sql queries correctly to get the desired output.

<body class="hi">

   <div class="container dt[-head-body]-center">
       <div class="row ">
           <div class="table">
            <hr>
            <table style="width:100%" class="table">
              <thead>
              
                 <tr>
    
               <th style="width:20%">ID</th>
               <th style="width:15%">Date / Time</th>
               <th style="width:15%">Location </th>
               <th style="width:15%">Team A</th>
               <th style="width:15%">Team B</th>
               <th style="width:10%">Score A</th>
               <th style="width:10%">Score B</th>
    
                  </tr>
                  
               </thead>
               <tbody>
               
               <?php
               
               
               $sql = "SELECT * FROM activitytable WHERE starttime  IN
               (
               SELECT starttime FROM activitytable 
               GROUP BY starttime HAVING count(*) > 1
               )";
               
               $res_data = mysqli_query($conn,$sql);
               
               while($row = mysqli_fetch_array($res_data)){
                   
               
               
               
               ?>

              <tr>
               
               <td><?= $row['id'] ?></td>
               <td><?= $row['starttime'] ?></td>
               <td><?= $row['location'] ?></td>
               
               <?php
               
               
               
               if ($row['team'] = 1) 
               {
               ?>
               <td>
               <?php
               echo $row["person"];
               echo "<br>";
               echo $row["person"];
               echo "<br>";
               echo $row["person"];
               echo "<br>";
               echo $row["person"];
               echo "<br>";
               }
               ?>
               
               </td>
             if ($row['team'] = 2) 
               {
               ?>
               <td>
               <?php
               echo $row["person"];
               echo "<br>";
               echo $row["person"];
               echo "<br>";
               echo $row["person"];
               echo "<br>";
               echo $row["person"];
               echo "<br>";
               }
               ?>
               
               </td>
               
               <td><?= $row['team'] ?></td>
               <td><?= $row['scoreA'] ?></td>
               <td><?= $row['scoreB'] ?></td>
               
               <?php } ?>
              </tr>
               
              
               </tbody>
             </table>
            </div>
        </div>
    </div>

It needs to be grouped by starttime. when i exec the code above it doesnt group the startime, it creates a row for every person and it is just printing every persons name 4 teams in each row.

Team A and Team B columns need to get the players from either team 1 (Team A) or 2 (Team B)

So in the database will be 8 records for every game played.

id – AUTO INCREMENT
player – players name
starttime – time of activity
scoreA – score for team 1
team – either 1 or 2
scoreB – score for team 2
location – location activity was held.

i want the output to look like this. Cant seem to figure it out, new to php sql

thanks

Exit mobile version