动态表格式

时间:2013-12-07 08:20:42

标签: java php html mysql

我有这个表来动态显示我数据库中的数据

<table border="1">
        <th>PO</th>
        <th>Fuel Details ID</th>
        <th>Date</th>
        <th>Price</th>
        <th>Liters</th>
        <th>Previous Balance</th>
        <th>Hobo</th>
        <th>Truck ID</th>
        <th>Fuel Source</th>
        <th>Date</th>
        <th>Route</th>
        <th>Destination</th>
        <th>Number of Vans</th>
        <th>Stripping</th>
        <th>Truck ID</th>
        <th>Customer ID</th>
        <th>Driver ID</th>
        <th>PO ID</th>
        <th>Waybill ID</th>

        <?php do { ?>
        <tr>
            <td><?php echo $row_PKFD['tbl_po_id_po']; ?></td>
            <td><?php echo $row_PKFD['id_fuel_details']; ?></td>
            <td><?php echo $row_PKFD['fuel_details_date']; ?></td>
            <td><?php echo $row_PKFD['fuel_details_price']; ?></td>
            <td><?php echo $row_PKFD['fuel_details_liters']; ?></td>
            <td><?php echo $row_PKFD['fuel_details_previous_bal']; ?></td>
            <td><?php echo $row_PKFD['fuel_details_hobo']; ?></td>
            <td><?php echo $row_PKFD['tbl_truck_id_truck']; ?></td>
            <td><?php echo $row_PKFD['tbl_fuel_source_id_fuel_source']; ?></td>

            <?php do { ?>
            <td><?php echo $row_PKDD['delivery_details_date']?></td>
            <td><?php echo $row_PKDD['delivery_details_route']?></td>
            <td><?php echo $row_PKDD['delivery_details_destination']?></td>
            <td><?php echo $row_PKDD['delivery_details_van_no']?></td>
            <td><?php echo $row_PKDD['delivery_details_strip_stuff']?></td>
            <td><?php echo $row_PKDD['tbl_truck_id_truck']?></td>
            <td><?php echo $row_PKDD['tbl_customer_id_customer']?></td>
            <td><?php echo $row_PKDD['tbl_driver_id_driver']?></td>
            <td><?php echo $row_PKDD['tbl_po_id_po']?></td>
            <td><?php echo $row_PKDD['tbl_waybill_id_waybill']?></td>
        </tr>
        <?php } while ($row_PKDD = mysql_fetch_assoc($PKDD)); ?>
        <?php } while ($row_PKFD = mysql_fetch_assoc($PKFD)); ?>
</table>

第一个显示第一个实例,如果程序找到两个或多个与第一个实例相关的数据,它将生成另一个,这在下面的代码中,因为你可以看到我的问题是当我显示第一个和第一个实例的时候是对齐的,但是当程序找到另一个与第一个相关的数据时,它会生成另一个而不是第二个内联,我希望它显示第一个将与第二个实例对齐而第二个实例将是低于第二个

的第一个实例

What is being displayed

What i want displayed

第一张图片显示代码显示的内容

第二张图显示了我想要显示的内容

1 个答案:

答案 0 :(得分:1)

<table border="1">
    <tr>
        <th>PO</th>
        <th>Fuel Details ID</th>
        <th>Date</th>
        <th>Price</th>
        <th>Liters</th>
        <th>Previous Balance</th>
        <th>Hobo</th>
        <th>Truck ID</th>
        <th>Fuel Source</th>
        <th>Date</th>
        <th>Route</th>
        <th>Destination</th>
        <th>Number of Vans</th>
        <th>Stripping</th>
        <th>Truck ID</th>
        <th>Customer ID</th>
        <th>Driver ID</th>
        <th>PO ID</th>
        <th>Waybill ID</th>
    </tr>
    <?php do { ?>
        <tr>
            <td><?php echo $row_PKFD['tbl_po_id_po']; ?></td>
            <td><?php echo $row_PKFD['id_fuel_details']; ?></td>
            <td><?php echo $row_PKFD['fuel_details_date']; ?></td>
            <td><?php echo $row_PKFD['fuel_details_price']; ?></td>
            <td><?php echo $row_PKFD['fuel_details_liters']; ?></td>
            <td><?php echo $row_PKFD['fuel_details_previous_bal']; ?></td>
            <td><?php echo $row_PKFD['fuel_details_hobo']; ?></td>
            <td><?php echo $row_PKFD['tbl_truck_id_truck']; ?></td>
            <td><?php echo $row_PKFD['tbl_fuel_source_id_fuel_source']; ?></td>

            <?php 
            if(!mysql_fetch_assoc($PKDD)){
                ?><td colspan='10'></td><?php
            }else{
                ?>
                do {
                    $i=0;
                    if($i > 0){
                        ?></tr><tr><td coslpan='9'></td><?php
                    }
                    <td><?php echo $row_PKDD['delivery_details_date']?></td>
                    <td><?php echo $row_PKDD['delivery_details_route']?></td>
                    <td><?php echo $row_PKDD['delivery_details_destination']?></td>
                    <td><?php echo $row_PKDD['delivery_details_van_no']?></td>
                    <td><?php echo $row_PKDD['delivery_details_strip_stuff']?></td>
                    <td><?php echo $row_PKDD['tbl_truck_id_truck']?></td>
                    <td><?php echo $row_PKDD['tbl_customer_id_customer']?></td>
                    <td><?php echo $row_PKDD['tbl_driver_id_driver']?></td>
                    <td><?php echo $row_PKDD['tbl_po_id_po']?></td>
                    <td><?php echo $row_PKDD['tbl_waybill_id_waybill']?></td>
                    if($i > 0){
                        ?></tr><tr><?php
                    }
                    $i++;   
                } while ($row_PKDD = mysql_fetch_assoc($PKDD));
            } 
            ?>
        </tr>
    <?php } while ($row_PKFD = mysql_fetch_assoc($PKFD)); ?>
</table>