odinnightowl Posted May 11, 2014 Share Posted May 11, 2014 hi im looking to turn the list i currently have into a table with 3 columns of 13 items each how would i go about doing that and what is the code? ive tried several and none seem to work best ive gotten was the line seperated into 3 groups of 13 but it is still a long list not the neat looking 3 rows left right and center. I am new at this and need an answer asap please. and please make it as simple as possible. if need be i can attach the file. Quote Link to comment https://forums.phpfreaks.com/topic/288398-tablechart-formating-issues/ Share on other sites More sharing options...
Ch0cu3r Posted May 11, 2014 Share Posted May 11, 2014 So you have 39 items in the list and you want to distribute them evenly across three columns on your webpage? It would be helpful if you could post an example of the data you're working with and your current code. Quote Link to comment https://forums.phpfreaks.com/topic/288398-tablechart-formating-issues/#findComment-1479068 Share on other sites More sharing options...
Cornelius Posted May 11, 2014 Share Posted May 11, 2014 Is 39 the final number of items? I suppose you're making a table in HTML and formatting it with CSS? Quote Link to comment https://forums.phpfreaks.com/topic/288398-tablechart-formating-issues/#findComment-1479084 Share on other sites More sharing options...
Barand Posted May 11, 2014 Share Posted May 11, 2014 Here's one way <?php // CREATE AN ARRAY OF 39 ITEMS AS TEST INPUT $arr = array(); for ($i=1; $i<=39; $i++) $arr[] = "ITEM $i"; // BREAK ARRAY INTO CHUNKS OF 3 ITEMS $chunks = array_chunk($arr, 3); // OUTPUT THE ARRAY IN A 3-COLUMN TABLE echo "<table border='1' cellpadding='2'>"; foreach ($chunks as $chunk) { echo "<tr><td>" . join("</td><td>", $chunk) . "</td></tr>"; } echo "</table>"; ?> Gives Quote Link to comment https://forums.phpfreaks.com/topic/288398-tablechart-formating-issues/#findComment-1479117 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.