我有问题, 我想创建一个保存表格内容的变量, 这是代码:
<?php
include 'koneksi.php';
$query = "SELECT transaksi.id as id, transaksi.deskripsi as deskripsi,
sum(case when shift='1' then transaksi.jumlah end) as shift1,
sum(case when shift='2' then transaksi.jumlah end) as shift2,
sum(transaksi.jumlah) as total
from transaksi where tanggal='2014-11-15' group by id, deskripsi";
$data1 = mysql_query($query) or die('Invalid query: ' .mysql_error());
$no=1;
while($row = mysql_fetch_object($data1)){
$output="
<table>
<tr>
<td>".$no++."</td>
<td>".$row->id."</td>
<td>".$row->deskripsi."</td>
<td>".$row->shift1."</td>
<td>".$row->shift2."</td>
<td>".$row->total."</td>
</tr>
</table>";}
echo $output;
?>
上面的代码显示了结果:
3 7100-04000 FINISH GOOD 32100-KVY-7000 20 11 31
结果仅显示查询的最后一条记录,
应该是这样的:
1 7100-00000 FINISH GOOD 32100-KZRM-B200 10 9 19
2 7100-03000 FINISH GOOD 32100-KVB-N700 7 8 15
3 7100-04000 FINISH GOOD 32100-KVY-7000 20 11 31
请帮忙,因为我想在php邮件中使用$ output作为$ body。
谢谢。
答案 0 :(得分:1)
试试这个:
echo "<table>";
while($row = mysql_fetch_object($data1)){
echo "<tr>
<td>".$no++."</td>
<td>".$row->id."</td>
<td>".$row->deskripsi."</td>
<td>".$row->shift1."</td>
<td>".$row->shift2."</td>
<td>".$row->total."</td>
</tr>";}
echo "</table>";
或者如果你想使用变量
$output = "<table>";
while($row = mysql_fetch_object($data1)){
$output .= "<tr>
<td>".$no++."</td>
<td>".$row->id."</td>
<td>".$row->deskripsi."</td>
<td>".$row->shift1."</td>
<td>".$row->shift2."</td>
<td>".$row->total."</td>
</tr>";}
$output .= "</table>";
echo $output;
答案 1 :(得分:0)
试试这个 -
$output = '<table>';
while($row = mysql_fetch_object($data1)){
$output .= "
<tr>
<td>".$no++."</td>
<td>".$row->id."</td>
<td>".$row->deskripsi."</td>
<td>".$row->shift1."</td>
<td>".$row->shift2."</td>
<td>".$row->total."</td>
</tr>";
}
$output .= "</table>";
echo $output;
答案 2 :(得分:0)
echo "<table>";
while($row = mysql_fetch_object($data1)){
$output=?>
<tr>
<td><?php echo $no++;?></td>
<td><?php echo $row->id;?></td>
<td><?php echo $row->deskripsi;?></td>
<td><?php echo $row->shift1;?></td>
<td><?php echo $row->shift2;?></td>
<td><?php echo $row->total;?></td>
</tr>
<?php
}
echo $output;
?>
echo "</table>";