Jump to content

Table/chart formating issues


odinnightowl

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/288398-tablechart-formating-issues/
Share on other sites

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

 

post-3105-0-41480500-1399842608_thumb.png

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.