0

I am creating a table that loops information from my database. I created the table with html and added styling via an external css sheet. The table format is not displaying in any way. None of the borders are displaying and the 100% width is not working. Could my while loop be causing this affect?

<table class="tableproduct">
                        <tr>
                            <th class="thproduct">Product ID</th>
                            <th class="thproduct">Product Name</th>
                            <th class="thproduct">Price</th>
                            <th class="thproduct">Category</th>
                            <th class="thproduct">Description</th>
                        </tr>   
 <?php                  
    while($row = mysqli_fetch_assoc($q)) : ?>

                        <tr>
                            <td class="tdproduct"><?php echo $row['product_id']; ?> </td>
                            <td class="tdproduct"><?php echo $row['name']; ?> </td> 
                            <td class="tdproduct"><?php echo $row['price']; ?> </td>
                            <td class="tdproduct"><?php echo $row['category']; ?> </td>
                            <td class="tdproduct"><?php echo $row['description']; ?> </td>
                        </tr>
                    </table>    
<?php   endwhile; ?>


.tableproduct {
width: 100%;
border: 1px solid black;
}
.tdproduct {
    border: 1px solid black;
}
.thproduct {
    height: 100px;
    border: 1px solid black;
}
2
  • Please provide your while loop codes.. Commented Apr 12, 2015 at 7:10
  • I fixed it. The php didn't space right, causing it to appear as a gap in between the table code when the code was originally posted. Commented Apr 12, 2015 at 7:16

1 Answer 1

1

I ended up resolving this.

I had to put an if statement with the while loops and it created the results I was looking for.

I added this to the while loop:

if( $result ){  
    while($row = mysqli_fetch_assoc($result)) :
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.