Skip to content

Instantly share code, notes, and snippets.

@hanafiah
Created December 29, 2012 03:11
Show Gist options
  • Save hanafiah/4404320 to your computer and use it in GitHub Desktop.
Save hanafiah/4404320 to your computer and use it in GitHub Desktop.
<?php
/**
* sample sql
*
SELECT
a.state, count(b.id) AS total
FROM state a
LEFT JOIN data b ON a.id=b.state_id
GROUP BY a.id
*
*/
$sample_result = array(
array(
'state' => 'johor',
'total' => 87851
),
array(
'state' => 'kedah',
'total' => 4626
),
array(
'state' => 'kelantan',
'total' => 894
),
array(
'state' => 'melaka',
'total' => 2129
)
);
$stateRow = '';
$totalRow = '';
foreach ($sample_result as $row) {
$stateRow .= '<td>' . $row['state'] . '</td>';
$totalRow .= '<td>' . $row['total'] . '</td>';
}
echo '<table border="1">';
echo '<tr><td>Negeri</td>' . $stateRow . '</tr>';
echo '<tr><td>Bilangan</td>' . $totalRow . '</tr>';
echo '</table>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment