根据数据库中的数据显示编号顺序

时间:2015-05-04 14:40:20

标签: php numbers sequence

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>";    
?>

感谢。

2 个答案:

答案 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 :(得分:0)

@Hardy Change。$ ++ i。 to。++ $ i。