So habe ich diese Tabellen in meiner Datenbank, die ich als Tabelle in HTML anzeigen muss. Das Problem ist, ich weiß nicht, wie ich meine td mit meinem th inline und addiere Null zu der Person, die keine Erlaubnis hat.Inline-Td mit th Verwendung von Schleife in PHP
Dies ist das Bild meiner Toleranztabelle
Bisher das ist, was ich habe:
<?php
error_reporting(0);
include "./includes/connectdb.php";
$emp = "select * from employee";
$q = $dbhandle->query($emp);
if($q->num_rows>0){
$all = "select distinct allowance from emp_allowances order by allowance asc";
$a = $dbhandle->query($all);
if($a->num_rows>0) {
while($b = $a->fetch_assoc()){
$thallowance .= '<th>'.$b['allowance'].'</th>';
$empallowance = $b['allowance'];
}
}
while($r = $q->fetch_assoc()){
$id= $r['id'];
$name= $r['name'];
$all2 = "select * from emp_allowances order by allowance asc";
$c = $dbhandle->query($all2);
if($c->num_rows>0){
$tdallow='';
while($d = $c->fetch_assoc()){
$empid = $d['emp_id'];
$empallowance = $d['allowance'];
$amount = $d['amount'];
if($empid==$id){
$tdallow.='<td>'.$amount.'</td>';
}
}
}
$tbody .= '<tr>
<td>'.$name.'</td>
'.$tdallow.'
</tr>';
}
}
$thead = '
<thead>
<tr>
<th>Name</th>
'.$thallowance.'
</tr>
</thead>
';
?>
<table border=1>
<?php echo $thead; ?>
<tbody>
<?php echo $tbody; ?>
</tbody>
Und aus diesem Code habe ich dieses Ergebnis.
In der Tabelle zum Beispiel, die einzige "Kleidung" Wert "500", während das Ergebnis der "Kleidung" Spalte 250 und 150 ist ebenfalls enthalten! Sehr gemischt sind die Werte! –