0

i want result like this in view.

result

This is (part of) the array:

Array ( [0] => Array ( [car_id] => ferarri [total] => 15 ) [1] => Array ( [car_id] => lamborgini [total] => 10 ) [2] => Array ( [car_id] => ford [total] => 32 ) [3] => Array ( [car_id] => toyota [total] => 45 ) [4] => Array ( [car_id] => viar [total] => 1 ) ) 1

how do I make it look. horizontally displays the total. and vertical displays car brand.

6
  • What is your expected result? Commented Mar 30, 2016 at 4:14
  • I've changed my question Commented Mar 30, 2016 at 4:16
  • 1
    just use a <table> tag if you want a presentation like that Commented Mar 30, 2016 at 4:17
  • Please explain about your expected result by image or something else. Commented Mar 30, 2016 at 4:18
  • Please post complete array . Commented Mar 30, 2016 at 4:26

1 Answer 1

1

You can use this

<?php 
$car_tot = array(
  '0' => array ( 
    'car_id' => 'ferarri',
    'total' => 15 
  ), 
  '1' => array (
    'car_id' => 'lamborgini',
    'total' => 10 
  ), 
  '2' => array (
    'car_id' => 'ford',
    'total' => 32 
  ), 
  '3' => array ( 
    'puskesmas_id' => 'toyota',
    'total' => 45 
  ), 
  '4' => array (
    'car_id' => 'viar',
    'total' => 1 
  )
);

echo '<pre>';
print_r( $car_tot );
echo '</pre>';
?>
<table>
<tr>
  <th>Type</th>
  <th>Total</th>
</tr>

<?php 
foreach( $car_tot as $key=>$ctRow )
{
   ?>
  <tr>
    <td>
        <?= !empty( $ctRow['car_id'] ) ? $ctRow['car_id'] : '';?>
    </td>
    <td>
       <?= !empty( $ctRow['total'] ) ? $ctRow['total'] : '';?>
    </td>
  </tr>
  <?php 
}
?>
</table>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.