scriptjet Posted January 11, 2011 Share Posted January 11, 2011 I'm teaching myself php and mysql -- and my coding is a little rough. But what i'm trying to do is display information from a mysql table in another table on a website. I can do this just fine simply displaying the table, but i want a little something different. I am only displaying one column of the table, instead of displaying it all in one column, i want to display the information in 5 columns. for example..... the table from mysql has names scott, john, james, mary, simon. with the code I have i can make it display like this: scott scott scott scott scott john john john john john james james james james james mary mary mary mary mary simon simon simon simon simon i want it to diplay like this: scott john james mary simon new names will continue down here is my code: <?php require ("connectigb.php"); $result = mysql_query ("SELECT pledgeName FROM pledgewall"); $fields_num = mysql_num_fields($result); echo "<center> <h1>TSA It Gets Better Pledge Wall</h1>"; echo "<table border='1' align='center' style='width:960px;'><tr>"; while($row = mysql_fetch_row($result)) { echo "<tr>"; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row as $cell) if ($cell != "") { for ($j=0; $j<5; $j++) { echo "<td>$cell</td>"; } } echo "</tr>\n"; } mysql_free_result($result); echo "</table></center>"; ?> any ideas on what i can do here, i'm sure this is a simply fix. i just haven't come across it yet. thanks for the help in advance. Link to comment https://forums.phpfreaks.com/topic/224086-really-simple-question/ Share on other sites More sharing options...
litebearer Posted January 11, 2011 Share Posted January 11, 2011 This thread may be of use http://www.phpfreaks.com/forums/faqcode-snippet-repository/multi-column-results/msg1506799/#new Link to comment https://forums.phpfreaks.com/topic/224086-really-simple-question/#findComment-1157902 Share on other sites More sharing options...
scriptjet Posted January 11, 2011 Author Share Posted January 11, 2011 that was absolutely what i needed, thank you so much. been looking at this for almost a week now. Link to comment https://forums.phpfreaks.com/topic/224086-really-simple-question/#findComment-1157913 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.