How to remove table head <th> gap

129 Views Asked by At

I have 6 table head and 6 table data, but there a gap of table head there as you can see from the image, but how to remove the gap? There are 6 table head but I need 7 table data to make it equal......

As shown in this picture:

For more clarity I set all td and th back ground as black (6 th and 6 td):

Coding:

<table class="table table-bordered" style='padding: 20px 20px;display:table-header-group;table-layout: fixed;'>
        <tr>
            <th>Date</th>
            <th>Time</th>
            <th>Product<th>
            <th>Quantity</th>
            <th>Price</th>
            <th>Payment Method</th>
        </tr>

        <?php

        while($row=mysqli_fetch_array($res)){                    
            echo "<tr>";
            echo "<td>"; echo $row['orderdate']; echo "</td>";
            echo "<td>"; echo $row['ordertime']; echo "</td>";
            /////////////////productname
            echo "<td>";
            echo "<table>";           

            while($row2=mysqli_fetch_array($res2)){

            echo "<tr>";
            echo "<th>"; echo $row2['listingname']; echo "</th>";
            echo "</tr>";
            }

            echo "</table>";
            echo "</td>"; 
            echo "<td>"; echo "qty"; echo "</td>";
            echo "<td>"; echo "price"; echo "</td>";
            echo "</tr>";

            }
        ?>
    </table>
2

There are 2 best solutions below

0
On BEST ANSWER

So actually I miss out one /th at end of product, thanks for everyone who helping

 <tr>
                        <th>Date</th>
                        <th>Time</th>
                        <th>Product</th>
                        <th>Quantity</th>
                        <th>Price</th>
                        <th>Payment Method</th>
                    </tr>
0
On

In your code you're declaring 6 columns and only feel 3 of them.

So in order to make it right you should add a colspan to your last td like the following code:

<table class="table table-bordered" style='padding: 20px 20px;display:table-header-group;table-layout: fixed;'>
    <tr>
        <th>Date</th>
        <th>Time</th>
        <th>Product<th>
        <th>Quantity</th>
        <th>Price</th>
        <th>Payment Method</th>
    </tr>
    <?php

        while($row=mysqli_fetch_array($res)){                    
            echo "<tr>";
            echo "<td>"; echo $row['orderdate']; echo "</td>";
            echo "<td>"; echo $row['ordertime']; echo "</td>";
            /////////////////productname
            echo "<td colspan='4'>";
            echo "<table>";           

            while($row2=mysqli_fetch_array($res2)){

                echo "<tr>";
                echo "<th>"; echo $row2['listingname']; echo "</th>";
                echo "</tr>";
            }

            echo "</table>";
            echo "</td>"; 

            echo "</tr>";

        }
    ?>
</table>