我有一个PHP代码,我正在为我的页面写作。它为我的朋友显示来自Facebook的信息,我已将其存储在一个数组中。我试图找到一种方法,每4个TD添加一行</tr><tr>
。怎么能实现这一目标?我使用的代码如下:
<div id="spouse">
<table width="100%" border="0">
<tr>
<td colspan="2" class="relationship_title">Girlfriend</td></tr>
<tr>
<td colspan="2"><?php
$pageContent = file_get_contents('http://graph.facebook.com/erin.craven.5');
$parsedJson = json_decode($pageContent);
echo $parsedJson->name;
echo " - ";
echo getAge("09/11/1992");
?></td>
</tr>
<tr>
<td width="150px"><img src="http://graph.facebook.com/erin.craven.5/picture?width=150&height=150"></td>
<td>About???</td>
</tr>
<tr><td colspan="2"><a href="<?php echo $parsedJson->link; ?>" target="_blank">Facebook</a> </td></tr>
</table>
</div>
<div id="friends">
<table width="100%" border="0">
<?php
$friends = array();
$friends[1] = "vonanita";
$friends[2] = "Steve3289";
$friends[3] = "100000358681483";
$friends[4] = "The.Gunslinger.Dancing.Deadman";
$friends[5] = "djstampfly";
$friends[6] = "sursie.merkel";
?>
<tr><td colspan="<?php echo count($friends); ?>" class="relationship_title">Friends</td> </tr>
<tr width="760px">
<?php
foreach ($friends as $friend)
{
echo "<td class='friendHold' width='177px'>";
$friendContent = file_get_contents('http://graph.facebook.com/'.$friend);
$friendparsedJson = json_decode($friendContent);
echo $friendparsedJson->first_name . " " . $friendparsedJson->last_name;
echo "<br><img src='http://graph.facebook.com/".$friend."/picture?width=150&height=150'> <br>";
echo $friendparsedJson->gender;
echo "<br>";
echo '<a href="http://facebook.com/' . $parsedJson->link . '" target="_blank">Facebook</a>';
echo "</td>";
}
?>
</tr>
我不知道从哪里开始。考虑到我正在使用foreach语句来处理我的数组中的所有内容,如何才能使每个TR只保留4个TD?