Skip to content Skip to sidebar Skip to footer

How To Format Data In Specific Way Using Html And Php

I have a table that contains Aspiring team for particular positions and various vote casted. The data is below Teamtable | no | team | position | votes Cast | | 1

Solution 1:

This could be very helpful for you

while($row = mysqli_fetch_assoc($result)) {
  $data[$row['position']]['total'][]=$row['votes'];
  $data[$row['position']][]=$row;
}
foreach($dataas$k=>$v){
    echo'<p>'.$k.'</p>';
    echo'<table border="1">';
    $total_votes=array_sum($v['total']);
    foreach($vas$kk=>$vv){
        if($kk!=='total'){
            $percentage=round($vv['votes']/$total_votes*100,2);
            echo'<tr><td>'.$vv['tean'].'</td><td>'.$vv['votes'].'</td><td>'.$percentage.'%</td></tr>';
        }
    }
    echo'</table>';
}

Solution 2:

You wan't to have the table on the outside of the foreach.

echo"<table>";
foreach($teamsas$re => $teas){
    $votes=$totalVotes[$re];
    echo"<tr>
            <td>$teas</td>
            <td>$votes</td>
         </tr>";
}
echo"</table>";

Post a Comment for "How To Format Data In Specific Way Using Html And Php"