MR.Internet
MR.Internet

Reputation: 645

Display array not the way I want

I have the following array in place

$array = 
(
    [0] => Array
        (
            [cnt_name] => germany
            [ent_func] => sec
            [COUNT(*)] => 31
        )

    [1] => Array
        (
            [cnt_name] => germany
            [ent_func] => Coach
            [COUNT(*)] => 1
        )

    [2] => Array
        (
            [cnt_name] => germany
            [ent_func] => officer
            [COUNT(*)] => 2
        )

    [3] => Array
        (
            [cnt_name] => france
            [ent_func] => manager
            [COUNT(*)] => 3
        )

    [4] => Array
        (
            [cnt_name] => france
            [ent_func] => sec
            [COUNT(*)] => 10
        )

)

What i need is to output the following table.

Country Name     sec   Coach   officer   
germany           31     1      2        
france            10     0      0         
--------------------------------------
Total             41     0      2        

I have tried as follows, But the output is wrong...

  <table class="table table-bordered table-striped">
            <tr>  
                <th><?= _('Name')?></th>
                <th><?= _('Sec')?></th> 
                <th><?= _('Coach')?></th>
                <th><?= _('officer')?></th>   
            </tr>  
            <?php foreach($array as $sbc) {?>
                <tr>   
                    <td><?=$sbc['cnt_name']?></td>  
                    <td><?php $sbc['ent_func'] == 'BX' ? 0 : ''?></td> 
                    <td><?=$sbc['COUNT(*)']?></td>   
                </tr>
                <?php } ?>
            <tr>   
                <td>Total</td>
                <td><span class="badge badge-info"><?=$summBoxer + $summOffic?></span></td>  
            </tr>
        </table>

Some one help Please?

Upvotes: 0

Views: 50

Answers (3)

Siakon
Siakon

Reputation: 13

I think you missed one <td></td> in your second <tr> and still in the Total you have only one <td></td>, but in your index table:

<tr>  
    <th><?= _('Name')?></th>
    <th><?= _('Sec')?></th> 
    <th><?= _('Coach')?></th>
    <th><?= _('officer')?></th>   
</tr>

there are 4 td's, you can either balance it with a colspan or with placing the proper number of td's. As i can see in the output you want you have to balance them.

Upvotes: 0

FBHY
FBHY

Reputation: 1004

You forgot the echo

 <td><?=($sbc['ent_func'] == 'BX') ? 0 : ''?></td>

Upvotes: 2

Krish R
Krish R

Reputation: 22721

You have missed to add echo $sbc['ent_func']

<td><?php echo $sbc['ent_func'] == 'BX' ? 0 : '';?></td> 

Or

<?=($sbc['ent_func'] == 'BX') ? 0 : '';?>

Upvotes: 1

Related Questions