This is the data on the table.
id, grpa, grpb
1, 1, 5
2, 4, 6
3, 8, 9
4, 3, 3
5, 5, 4
6, 7, 8
7, 9, 10
8, 10, 5
9, 10, 9
and this the desired table from the original table.
I showed the expected table in horizontal view to prevent confusion. My real table is vertical in the code.
I tried this before, it lists all category keys in the html table.
It's supposed to list only the category key numbers that matches the value, if not the output to be blank.
How can I get rid of "Notice:Array to string conversion on line 78" error from this code? can i get a little help please?
This is line 78 : $table .= $columnValue;
Basically this code's supposed to do is to group the values from grpa, grpb of datatb to 4 different categories according to their value. and as end result, category index number of each category is put into the html table.
Thanks.
<?php
include ("configd.php");
$sql = "SELECT grpa, grpb From datatb";
$result = $conn->query($sql);
//categories
$cat = [
4 => [1, 2, 3, 4],
3 => [5, 6],
2 => [7, 8],
1 => [9, 10]
];
while ($row = $result->fetch_assoc()) {
foreach ($cat as $catKey => $catValue) {
$columns[$catKey] = array_filter($row, function ($col) use ($cat, $catKey) {
if (in_array($col, $cat[$catKey])) {
return true;
}
});
}
$output[] = $columns;
}
// the output
$table = <<<EOT
<table class='maintable'>
<tr><th>9:10</th></tr>
<tr><th>7:8</th></tr>
<tr><th>5:6</th></tr>
<tr><th>1:4</th></tr>
</table>
EOT;
foreach ($output as $row) {
$table .= "<table class='maintable'>";
foreach ($row as $columnKey => $columnValue) {
$table .= "<tr>";
$table .= "<td>";
$table .= $columnValue;
$table .= "</td>";
}
$table .= "</tr>";
$table .= "</table>";
}
echo $table;
?>
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.