私はこのテーブルを自分のデータベースにhtmlの表として表示する必要があります。問題は、私がどのようにして自分のtdをインラインでインライン化し、余裕のない人にゼロを追加するのか分かりません。インラインtdとPHPのループを使用
これは私の代表
は、これまでのところ、これは私が持っているものです。
<?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>
、私はこの結果を得た。このコードから。
「衣類」の値が「500」のみであり、「衣類」の欄250および150の結果も含まれています。非常に混在して値があります! –