oraya Posted July 8, 2012 Share Posted July 8, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/265394-populating-a-html-table-across-with-data-from-mysql/ Share on other sites More sharing options...
oraya Posted July 8, 2012 Author Share Posted July 8, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/265394-populating-a-html-table-across-with-data-from-mysql/#findComment-1360146 Share on other sites More sharing options...
Barand Posted July 8, 2012 Share Posted July 8, 2012 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>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/265394-populating-a-html-table-across-with-data-from-mysql/#findComment-1360149 Share on other sites More sharing options...
oraya Posted July 8, 2012 Author Share Posted July 8, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/265394-populating-a-html-table-across-with-data-from-mysql/#findComment-1360151 Share on other sites More sharing options...
oraya Posted July 8, 2012 Author Share Posted July 8, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/265394-populating-a-html-table-across-with-data-from-mysql/#findComment-1360162 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.