php - Displaying multiple records in one row with duplicate user id -


i have table setup awards tracked user id. there multiple records same user id different awards.

current database

+---------+----------+---------------------+ | user_id | award_id | award_date          | +---------+----------+---------------------+ |       1 |       26 | 2016-08-20 00:00:00 | |       1 |       27 | null                | |       1 |       28 | null                | |       1 |       29 | null                | |       1 |       30 | null                | |       1 |       31 | null                | |       2 |       26 | 2016-08-19 00:00:00 | |       2 |        2 | null                | |       3 |       36 | null                | |       3 |        2 | null                | |       4 |        1 | null                | |       4 |        2 | null                | |       5 |        1 | null                | |       5 |        2 | null                | |       6 |        6 | 2016-08-23 23:06:48 | |       6 |        1 | null                | |       2 |       20 | null                | |       3 |       20 | 2016-08-18 00:00:00 | |       4 |       20 | null                | |       5 |       20 | null                | +---------+----------+---------------------+ 

the current code using not able display records user. grab single result. have tried removing group needs keep records 1 row multiple results.

$sql = "select * awards order id asc"; $results = mysqli_query($con, $sql); $awards = array(); while ( $row = mysqli_fetch_assoc($results) ) {     $awards[] = $row; }  $asql = "select * ( awards, rosters ) inner join ranks on ranks.id=rosters.rankid inner join user_awards on user_awards.award_id=awards.id rosters.ruser_id = user_awards.user_id , rosters.rplatoon='viking' group rosters.rname order rosters.rname"; $aresults = mysqli_query($con, $asql); if(!$aresults , $mysqlidebug) {     echo "<p>there error in query:". $aresults."</p>";     echo $con->error; }  $uawards = array(); while ( $arow = mysqli_fetch_assoc($aresults) ) {     $uawards[] = $arow; } ?>  <table >     <thead>         <tr>             <th>rank/name</th>             <?php foreach ($awards $award)              {                  if ($award['category'] == 'medal')                  {                     echo '<th style="text-align:center;">                               <div class="tooltip4">                                   <div id="award-'. $award['image_name'] . '3">&nbsp;</div>                                   <span class="tooltiptext4">'. $award['award_name'] .'</span>                               </div>                           </th>';                   }                  }              ?>             </tr>       </thead>       <tbody>           <?php foreach ($uawards $users )            {                echo '<tr><td>' . $users['name'] . ' '. $users['rname'] . '</td>';                      $medal = 0;                      foreach ($awards $award)                      {                           if ( $award['category'] == 'medal')                           {                               if ( $award['id'] == $users['award_id'])                               {                                   $awardid = $users['award_id'];                                   if ( $awardid == 26 )                                   {                                       echo '<td>true</td>';                                   }                                   elseif ( $awardid = 27 )                                   {                                       echo '<td>true</td>';                                   }                                   elseif ( $awardid = 28 )                                   {                                       echo '<td>true</td>';                                   }                                   elseif ( $awardid = 29 )                                   {                                       echo '<td>true</td>';                                   }                                   elseif ( $awardid = 30 )                                   {                                       echo '<td>true</td>';                                   }                                   elseif ( $awardid = 31 )                                   {                                       echo '<td>true</td>';                                   }                                   elseif ( $awardid = 32 )                                   {                                       echo '<td>true</td>';                                   }                                   elseif ( $awardid = 33 )                                   {                                       echo '<td>true</td>';                                   }                                   elseif ( $awardid = 34 )                                   {                                       echo '<td>true</td>';                                   }                                   elseif ( $awardid = 35 )                                   {                                       echo '<td>true</td>';                                   }                                   elseif ( $awardid = 36 )                                   {                                       echo '<td>true</td>';                                   }                                   elseif ( $awardid = 37 )                                   {                                       echo '<td>true</td>';                                   }                                   elseif ( $awardid = 38 )                                   {                                       echo '<td>true</td>';                                   }                                   elseif ( $awardid = 39 )                                   {                                       echo '<td>true</td>';                                   }                                   elseif ( $awardid = 40 )                                   {                                       echo '<td>true</td>';                                   }                                   elseif ( !$awardid )                                   {                                       echo '<td>true</td>';                                   }                               }                               else                               {                                   echo '<td>false</td>';                               }                           }                       }                       echo '</tr>';                   }              ?>     </tbody> </table> 

here result

enter image description here

i hope worded correctly.

thanks in advance

$asql =   select user_id,group_concat(award_id separator ',') awards user_awards group user_id $aresults = mysqli_query($con, $asql); 

it gives 1 row in comma separated (in awards 26,27,28,29,30,31 against user_id 1) use explode function , in_array()

   <table >       <thead>          <tr>             <th>rank/name</th>             <?php foreach ($awards $award)             {                if ($award['category'] == 'medal')                {                   echo '<th style="text-align:center;">                   <div class="tooltip4">                       <div id="award-'. $award['image_name'] . '3">&nbsp;</div>                       <span class="tooltiptext4">'. $award['award_name'] .'</span>                   </div>                   </th>';                }               }           ?>         </tr>      </thead>      <tbody>         while($arow = mysqli_fetch_assoc($aresults)         {            <tr>                $award=explode(',',$arow['awards'])?>                <td>                <?php                    if (in_array("26", $award)) echo "true";                     else  echo "false";                 ?>                </td>                <td><?php                   if (in_array("27", $award)) echo "true";                    else  echo "false";                 ?></td>            </tr>          }?>     </tbody>  <table> 

this example of 2 columns, more columns add them while loop

<td><?php     if (in_array("award_id", $award))`replace award_ids table ids`         echo "true";      else  echo "false";      ?> </td> 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -