2015-05-04 129 views
0

enter image description here根据数据库中的数据数显示数字序列

如何根据数据库中的数据显示数量。

例如,上面的图片显示了数据库中的数据摘录。在我的数据库中有两个数据。因此,我想在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>";  
?> 

感谢。

+0

你能告诉我们打印这张表的代码吗? – Halcyon

+0

据我所知,**没有**列没有值... – sitilge

+0

它很简单,你可以采取'$计数器',并实现这一点 –

回答

1

尝试用下面的代码:

<?php 
$i = 0; 
$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'>".$++i."</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>";  
?> 
+1

你的_No_列从'0'开始。既可以做'$ i = 1'或'++ $ i'。 – Halcyon

+0

@Halcyon ..谢谢男人.. !!代码已更新 –

0

@Hardy更改$ ++我。到。++ $ i。