Monday, 15 March 2010

php - Explode and foreach to create multi table -



php - Explode and foreach to create multi <td> table -

i'm using explode() take apart paragraphs individual words. works great. looping through foreach(). works great. nil complicated here.

$title_pieces = explode(" ", $title_fixed); foreach($title_pieces $tpiece){ echo "<b>$tpiece<br>"; }

unfortunately returns ugly long list of words. i'd can't quite figure out how set in nice table. creating table no problem, part can't figure out how write more 1 $tpiece per row. i'd have maybe 5 <td>s in each row.

so if do:

foreach($title_pieces $tpiece){ echo "<tr><td>$tpiece</td></tr>"; }

i'm still left long list. can point me in right direction here. give thanks you

just sample-code. work around modulo-operator.

<?php $i = 1; echo '<table><tr>'; foreach($title_pieces $tpiece){ if ($i % 10 == 0) echo "</tr><tr>"; echo "<td>$tpiece</td>"; $i++; } echo '</tr></table>'; ?>

php html table loops foreach

No comments:

Post a Comment