I've been on this code for almost a week and can't seem to get out of it. I'm fetching rows from a database that looks like this:
id | account | content | type | quantity
1 23494 E 38 10
2 23494 E 13 5
3 23494 F 38 7
4 23494 E 6 2
My Statement looks like this thus far:
// Make the query:
$qu = "SELECT * FROM log WHERE account='".$account."' ORDER BY timelog DESC $pages->limit";
$re = @mysqli_query ($dbc, $qu); // Run the query.
$roarr = array();
while ($row = mysqli_fetch_array($re, MYSQLI_ASSOC)) {
$roarr[$row['account']][$row['content']][$row['type']] = $row['quantity'];
} // End of WHILE loop.
//print_r($roarr);
echo'
<tr> </tr>
<tr>
<td align="left"><b>Account</b></td>
<td align="left"><b>6Kg(E)</b></td>
<td align="left"><b>13Kg(E)</b></td>
<td align="left"><b>38Kg(E)</b></td>
<td align="left"><b>6Kg(F)</b></td>
<td align="left"><b>13Kg(F)</b></td>
<td align="left"><b>38Kg(F)</b></td>
<td align="left"><b>Date Created</b></td>
</tr>
';
$dataarr = array();
foreach($roarr as $account => $dataarr) {
$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');
echo '
<tr bgcolor="' . $bg . '">
<td align="left">'. $account .'</td>
';
foreach($dataarr as $content => $data) {
if($content == "E") {
echo '<td align="left">', (isset($data['6']) ? $data['6'] : ' '), '</td>';
echo '<td align="left">', (isset($data['13']) ? $data['13'] : ' '), '</td>';
echo '<td align="left">', (isset($data['38']) ? $data['38'] : ' '), '</td>';
} // Then I GET STUCK on the Else Part! HOW Do I display $content == "F" data on the right hand side?
} //End Foreach
} //End Foreach
This is how I intend to display my results :
Account | 6KG(E) | 13KG(E) | 38KG(E) | 6KG(F) | 13KG(F) | 38KG(F) | Date
23494 5 10 2 7
, but I'm so stuck.
Question: How can I arrange the results fetched in such a format?
EDIT: I've Changed the database so as to focus more on the problem: Since the query fetches per account, there is only one account with rows shown as in the database above.
This is the array produced by $roarr:
Array ( [23494] => Array ( [F] => Array ( [6] => 2 [38] => 7 ) [E] => Array ( [38] => 10 [13] => 5 ) ) )
Thank You in Advance