0

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;

}
2
  • 1
    You could create a new table for each result and set "margin-bottom" in the CSS to make the tables appear separate. Commented Mar 10, 2013 at 21:27
  • And a decent template system. Commented Mar 10, 2013 at 21:27

1 Answer 1

1

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;    
}
Sign up to request clarification or add additional context in comments.

1 Comment

ur suggested solution works just the way i wanted it to be many thx

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.