Angeleyezz Posted May 19, 2009 Share Posted May 19, 2009 ok, basically i have a table in my database, it has 2 fields in it, 1 is an ID field which i dont need thats just the unique identifier, the other is a specific name, the specific name is what i need to query to the website. now i know i can throw it in a loop and have it cycle through all the data posting a a verticle cell, or a horizontal row, whatever..... what i want to do is break that data up into multiple cells & rows on the output.... like 3 columns and say 20 rows down example: data data data data data data data data data data data data the only thing i know how to do is data data data data data data data which is not what i want... i want it listed like above.... is there any way possible do achieve this, something i must just be too stupid to figure out. any help would greatly be appreciated, and i thank anyone in advance. Quote Link to comment https://forums.phpfreaks.com/topic/158740-noob-table-output-help/ Share on other sites More sharing options...
Angeleyezz Posted May 19, 2009 Author Share Posted May 19, 2009 oops i also posted this in the wrong channel, and i just realized that.. sorry for that, if someone could move it to the appropriate area please. Quote Link to comment https://forums.phpfreaks.com/topic/158740-noob-table-output-help/#findComment-837195 Share on other sites More sharing options...
Ken2k7 Posted May 19, 2009 Share Posted May 19, 2009 You can do something along the lines of - <table><tr> <?php $sql = 'SQL HERE'; $result = mysql_query($sql); $cols_per_row = 4; $count = 0; while ($row = mysql_fetch_assoc($result)) { echo '<td>some data</td>'; if (++$count % $cols_per_row === 0) echo '</tr><tr>'; } ?> </tr></table> Quote Link to comment https://forums.phpfreaks.com/topic/158740-noob-table-output-help/#findComment-837262 Share on other sites More sharing options...
Angeleyezz Posted May 20, 2009 Author Share Posted May 20, 2009 The tables are working right, but now my code isnt lol. Error : PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\hshome\martinia\elitemartini.com\drinks.php on line 106 // Liquor List $get_liquors = "SELECT name from liquors_mixers"; $liquors_res = mysql_query($get_liquors); echo "<table width=\"100%\" border=\"1\"><tr>"; $cols_per_row =4; $count = 0; while ($row = mysql_fetch_array($liquors_res)) { echo "<td>$row['0']</td>"; if (++$count % $cols_per_row === 0) echo '</tr><tr>'; } echo "</tr></table>"; ?> Any Suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/158740-noob-table-output-help/#findComment-837895 Share on other sites More sharing options...
Angeleyezz Posted May 20, 2009 Author Share Posted May 20, 2009 Ok, fixed that problem, but now a new one arises with it. if there is less than 4 cells at the end, then it comes up like i never put anything on those cells, like for example <table> <tr> <td>1</td><td>2</td><td>3</td> </tr> <tr> <td>1</td> see then theres like white space on the rest and the table doesnt form properly Quote Link to comment https://forums.phpfreaks.com/topic/158740-noob-table-output-help/#findComment-837908 Share on other sites More sharing options...
Ken2k7 Posted May 20, 2009 Share Posted May 20, 2009 Put a space character - in the 4th column. Quote Link to comment https://forums.phpfreaks.com/topic/158740-noob-table-output-help/#findComment-838198 Share on other sites More sharing options...
Angeleyezz Posted May 30, 2009 Author Share Posted May 30, 2009 that works on a table? i thought that was only for formatting text lol Quote Link to comment https://forums.phpfreaks.com/topic/158740-noob-table-output-help/#findComment-845559 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.