仅显示一次具有相同名称的数据

时间:2014-02-04 12:04:32

标签: php mysql

我需要显示我的结算历史记录,因此用户可以通过点击提交自动提交。但是,我不必显示所有交易,而只需显示每个billing_name,因此我应该使用SELECT DISTINCT吗?

<?php
$query3 = "SELECT DISTINCT billing_name, billing_reference_num FROM billing_history";
$result3 = mysqli_query($link, $query3) or die(mysqli_error($link));
while ($row3 = mysqli_fetch_array($result3)) {
    $billing_name = $row3['billing_name'];
    $billing_reference_num = $row3['billing_reference_num'];
    ?>
    <td><?php echo $billing_name ?></td>
    <td><?php echo $billing_reference_num ?></td>
    <?php
    $queryBill = "SELECT * FROM billing_history WHERE billing_name = '$billing_name'";
    $resultBill = mysqli_query($link, $queryBill) or die(mysqli_error($link));
    while ($row4 = mysqli_fetch_array($resultBill)) {
        $billing_name_id = $row4['billing_name_id'];
        $account_id = $row4['account_id'];
        $account_number = $row4['account_number'];
    }
    ?>
    <td><input type="text" name="transaction_amount"/></td>
    <td><input type="submit" value="Submit"/></td>
    <input type="hidden" name="billing_name_id" value="<?php echo $billing_name_id ?>"/>
    <input type="hidden" name="billing_name" value="<?php echo $billing_name ?>"/>
    <input type="hidden" name="billing_reference_num" value="<?php echo $billing_reference_num ?>"/>
    <input type="hidden" name="account_number" value="<?php echo $account_number ?>"/>
    <input type="hidden" name="account_id" value="<?php echo $account_id ?>"/>

0 个答案:

没有答案