I have the following code where I try to print alphabets from a to z in the first column. but I only get the letter "a" is printed through the entire column.
function print_table_tb ($conn, $id) {
$sql = "SELECT stata,statb,statc FROM dbA";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table class='tbr' id='tb$id'>";
while($row = $result->fetch_assoc()) {
$data = array_reduce($row, function($carry, $value) {
$carry[] = "<td dbval='{$value}'>{$value}</td>";
return $carry;
}, []);
$range = range('a', 'z');
$i = 0;
echo '<tr><td class="tbe">'.$range[$i++ % 26].'</td>'. implode('', $data) . "</tr>\n" ;
}
echo "</table>";
}
}
What am I doing wrong here? thanks for your help! My question is different. I don't seek a solution to get alphabetical listing, I have the solution, but I couldn't fix an error.
I tried this but it doesn't work either.
function print_table_tb ($conn, $id) {
$sql = "SELECT stata,statb,statc FROM dbA";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$range = array("a", "b", "c", "d");
$i = 0;
echo "<table class='tbr' id='tb$id'>";
while($row = $result->fetch_assoc()) {
$data = array_reduce($row, function($carry, $value) {
$carry[] = "<td dbval='{$value}'>{$value}</td>";
return $carry;
}, []);
echo '<tr><td class="tbe">' . $range[$i] . '</td>'
. implode('', $data) . "</tr>\n" ;
$i++;
}
echo "</table>";
}
}