如何根据数据库中的数据显示数量。
例如,上面的图片显示了数据库中的数据摘录。在我的数据库中有两个数据。因此,我想在No栏中显示编号1和2。
如果数据库中有四个数据,我想在No列显示数字1,2,3和4。
编码来显示上述表
<?php
$sql= mysql_query ("SELECT * FROM employee INNER JOIN cash ON employee.emp_id = cash.emp_id WHERE cash_status='Pending'");
echo "<table id='dataTable' width='850' border='1' align='center'>";
echo "<tr>
<th height='50'>No</th>
<th height='50'>Employee Number</th>
<th height='50'>Name</th>
<th height='50'>Department</th>
<th height='50'>Date Apply</th>
<th height='50'>Date Cash To Be Use</th>
<th height='50'>Amount</th>
<th height='50'>Status</th>
<th height='50'>Cash Id</th>
<th height='50'>View</th>
</tr>";
while ($row = mysql_fetch_array($sql))
{
echo "<tr>";
echo "<td align='center' height='30'></td>";
echo "<td align='center' height='30'>" .$row['emp_id']. "</td>";
echo "<td align='center' height='30'>" .$row['emp_name']. "</td>";
echo "<td align='center' height='30'>" .$row['emp_department']. "</td>";
echo "<td align='center' height='30'>" .$row['cash_dapply']. "</td>";
echo "<td align='center' height='30'>" .$row['cash_duse']. "</td>";
echo "<td align='center' height='30'>RM" .$row['cash_amount']. "</td>";
echo "<td align='center' height='30'>" .$row['cash_status']. "</td>";
echo "<td align='center' height='30'>" .$row['cash_id']. "</td>";
echo"<td height='30'><a href= cadvance_approval.php?id=".$row['emp_id']."&cash_id=".$row['cash_id']."><img src='../img/view_user.png' width='20' height='20'></a></td>";
echo "</tr>";
}
echo "</table>";
?>
感谢。
你能告诉我们打印这张表的代码吗? – Halcyon
据我所知,**没有**列没有值... – sitilge
它很简单,你可以采取'$计数器',并实现这一点 –