Tomazi
Tomazi

Reputation: 791

PHP get database data into HTML table

I want to put my database data into HTML table and its not so easy as it seems, Look at my photographs and code to get better understanding on what my problem is

My Result:

enter image description here

Desired Result:

enter image description here

Basically i want to separate the results as the red line indicates so each item becomes seperate.

PHP code:

$sql = mysql_query("SELECT * FROM products"); ?>


<table id='display'>


    <?php
        while($rows = mysql_fetch_array($sql))
            {
    ?>
        <tr><td><?php echo "<img src=$rows[$product_image] height='200px' width='200px'>" ?></td></tr>

        <tr>
        <td><b><?php echo "$rows[$product_name]" ?></td>
        <td><b><?php echo "Avalible: $rows[$product_qua]" ?></td>
        <td><b><?php echo "Price: £ $rows[$product_price]" ?></td>
        <td><b><?php echo "Description: $rows[$product_des]" ?></td>
        </tr>
        <tr>
        <td><strong><p>Please Login To purchase this item </p></strong><a href="login.php">Login</a></td>
        </tr>

        <?php
            }
        ?>

</table>

CSS code:

table#display{
    float:left;
    border: 5px solid black;
    margin-top:50px;
    margin-left:10px;

}
table#display td{
    border: 1px solid black;
    padding:0 8px;

}
table#display tr{
    border: 1px solid black;
    padding:0 8px;

}

Upvotes: 0

Views: 9430

Answers (1)

alu
alu

Reputation: 759

My solution: PHP Code:

$sql = mysql_query("SELECT * FROM products"); ?>

<?php
    while($rows = mysql_fetch_array($sql))
        {
?>
<table class='display'>
    <tr><td><?php echo "<img src=$rows[$product_image] height='200px' width='200px'>" ?></td></tr>

    <tr>
    <td><b><?php echo "$rows[$product_name]" ?></td>
    <td><b><?php echo "Avalible: $rows[$product_qua]" ?></td>
    <td><b><?php echo "Price: £ $rows[$product_price]" ?></td>
    <td><b><?php echo "Description: $rows[$product_des]" ?></td>
    </tr>
    <tr>
    <td><strong><p>Please Login To purchase this item </p></strong><a href="login.php">Login</a></td>
    </tr>
    </table>

    <?php
        }
    ?>

The CSS:

table.display{
    float:left;
    border: 5px solid black;
    margin-top:50px;
    margin-left:10px;
    margin-bottom: 10px;    
}

Upvotes: 1

Related Questions