Manuel Acosta
Manuel Acosta

Reputation: 1

How can I add these results in php and get average

enter image description here

I want to take the data thrown in the td's and sum it up and then average it and then display it in Promedios, I have tried but I can't manage to add the result in that way, I already need a little more experience and at the moment it is not within my reach to solve it

<?php
$blocks = BlockData::getAllByTeamId($_GET["team_id"]);
?>
<div class="row">
    <div class="col-md-12">
        <h1>Calificaciones</h1>
        <?php if(count($blocks)>0):?>
            <a href="./report/califications-word.php?team_id=<?php echo $_GET["team_id"]; ?>" class="btn btn-default"><i class="fa fa-download"></i> Descargar</a>
        <?php endif; ?>
        <br><br>
        <?php

        $alumns = AlumnTeamData::getAllByTeamId($_GET["team_id"]);
        if(count($alumns)>0){
            // si hay usuarios
            ?>

            <table class="table table-bordered table-hover">
            <thead>
            <th>Nombre</th>
            <?php foreach($blocks as $block):?>
            <th><?php echo $block->name; ?></th>
            <?php endforeach; ?>
            <th>Promedio</th>

            </thead>
            <?php
            foreach($alumns as $al){
                $alumn = $al->getAlumn();
                ?>
                <tr>
                <td><?php echo $alumn->name." ".$alumn->lastname; ?></td>
            <?php foreach($blocks as $block):
            $val = CalificationData::getByBA($block->id, $alumn->id);
            ?>
                <td><?php if($val!=null ){ echo $val->val; }  ?></td>
            <?php endforeach; ?>

                </tr>
                <?php

            }
            echo "</table>";

        }else{
            echo "<p class='alert alert-danger'>No hay Grupos</p>";
        }


        ?>


    </div>
</div>

Upvotes: 0

Views: 57

Answers (1)

Nads
Nads

Reputation: 109

Please check the below solution and let me know if this meets your requirements. Feel free to drop a comment if you need something else.

    <div class="row">
<div class="col-md-12">
    <h1>Calificaciones</h1>
    <?php if(count($blocks)>0):?>
        <a href="./report/califications-word.php?team_id=<?php echo $_GET["team_id"]; ?>" class="btn btn-default"><i class="fa fa-download"></i> Descargar</a>
    <?php endif; ?>
    <br><br>
    <?php

    $alumns = AlumnTeamData::getAllByTeamId($_GET["team_id"]);
    if(count($alumns)>0){
        // si hay usuarios
        ?>

        <table class="table table-bordered table-hover">
        <thead>
        <th>Nombre</th>
        <?php foreach($blocks as $block):?>
        <th><?php echo $block->name; ?></th>
        <?php endforeach; ?>
        <th>Promedio</th>

        </thead>
        <?php
         $rows = 0;
         $grand_total = 0;
        foreach($alumns as $al){
            $alumn = $al->getAlumn();
            $rows ++;
            ?>
            <tr>
            <td><?php echo $alumn->name." ".$alumn->lastname; ?></td>
        <?php foreach($blocks as $block):
        $val = CalificationData::getByBA($block->id, $alumn->id);
        ?>
            <td><?php if($val!=null ){ echo $val->val; $grand_total = $grand_total  + $val; }  ?></td>
     

<?php endforeach; ?>
</tr>
                <?php

            }
            echo "</table>";

        }else{
            echo "<p class='alert alert-danger'>No hay Grupos</p>";
        }


        ?>


    </div>
</div>

Upvotes: 1

Related Questions