Jump to content

Populating a html table across with data from mysql


oraya
 Share

Recommended Posts

Is there a way to pull the data from the database to populate the html table going across and then down to the next row and across?

 

I'd like to place all the fields from the database in one td.  Like so:

 

CONTACT DETAILS:

 

Title                                |  Title                            |    And so forth there are three columns so another after this.

1st line address            |  1st line of address      |

2nd line address            |  2nd line of address    |

Town                              |  Town                          |

Post code                      |  Post code                    | 

 

The row then from the mysl is title, 1st_line, 2nd_line, Town, Postcode.

 

I can't figure out how I can populate the html fields across and then down onto the next row.

 

I hope this makes sense!

Oraya

Link to comment
Share on other sites

I'm thinking I would do it with a foreach in an array but can't figure out how to do it..  have googled for an answer and tried many things but can't get to work..  If someone is able to point me in the right direction I'd be very grateful.

 

Oraya

Link to comment
Share on other sites

try something like this

<?php
$sql = "SELECT title, 1st_line, 2nd_line, Town, Postcode
        FROM mytable";
$res = mysql_query($sql);

while (list($title, $line1, $line2, $town, $postcode) = mysql_fetch_row($res)) {
    echo "<div style='width:30%; float:left; margin-bottom:10px'>
        $title<br />
        $line1<br />
        $line2<br />
        $town<br />
        $postcode
    </div>";
}
?>

Link to comment
Share on other sites

Oh good call, duh why didn't I think of that?  I'll give that a go, thank you!  Been at it to long today...  I think my brain has gong into melt down.  :(

 

Thank you again,

Oraya

Link to comment
Share on other sites

try something like this

<?php
$sql = "SELECT title, 1st_line, 2nd_line, Town, Postcode
        FROM mytable";
$res = mysql_query($sql);

while (list($title, $line1, $line2, $town, $postcode) = mysql_fetch_row($res)) {
    echo "<div style='width:30%; float:left; margin-bottom:10px'>
        $title<br />
        $line1<br />
        $line2<br />
        $town<br />
        $postcode
    </div>";
}
?>

 

Brilliant works like a charm, thank you so much for your help! I'm very grateful..

Oraya

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.