/    Sign up×
Community /Pin to ProfileBookmark

table loop format question

hey,

Got a quick question, i know how to do a loop for a row and a # of columns for information from an array. that each row is information relating to think so it would be like


————-

| a |
————-


| b |
————-


| c |
————-

but i want to do is that have like 3 column per row and each column on that row be a different entry from a array so more like


————

| a | b | c |
————


| d | e | f |
————


| g | h | i |
————

with a, b, c, d, e, f, g, h, i each being something different, any one know how i could do this?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@UbikApr 18.2006 — Use something like 'if rows MOD 3=0 then output "<tr></tr>"

Enclose the whole thing in <tr> and </tr> and you're all set.
Copy linkTweet thisAlerts:
@welshauthorApr 18.2006 — could i get an example please?
Copy linkTweet thisAlerts:
@balloonbuffoonApr 18.2006 — Here's what I've done in the past:
[code=php]//populate results in an array
for ($i=1;$i<=10;$i++) { //create sample array
$results[] = $i;
}

$rows = array_chunk($results,3); //3 = number of columns

echo "<table border='1'>";
foreach ($rows as $row) {
echo "<tr>";
foreach ($row as $col) {
echo "<td>", $col, "</td>";
}
echo "</tr>";
}
echo "</table>";[/code]


--Steve
×

Success!

Help @welsh spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...