Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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