如何使每 4 列在表中成为自己的行?请不要告诉我我应该将它们作为 div 来做,这需要是一张桌子......
这是我的代码:
$tmpRet = array_filter($ret, function($e){
return ($e['categoryID'] == 6) ? $e : null;
});
$tmpRet = array_values($tmpRet);
$tmpCt = count($tmpRet);
$counter = 0;
echo '<table width="100%" cellpadding="10" cellspacing="5">' . PHP_EOL;
for($i = 0; $i < $tmpCt; ++$i){
$counter ++;
echo ($i == 0 || $i % 4 === 0) ? ' <tr>' . PHP_EOL : null;
echo '<td width="25%" align="center" valign="middle"><a href="' . $tmpRet[$i]['sponUrl'] . '" target="_blank"><img border="0" src="http://sparkusa.org/' . GetLogoPath($tmpRet[$i]['showType']) . '/images/sponsors/' . $tmpRet[$i]['sponFileName'] . '" alt="' . $tmpRet[$i]['sponName'] . '" title="' . $tmpRet[$i]['sponName'] . '" style="max-height:85px;" /></a></td>' . PHP_EOL;
echo ($i == 0 || $i % 4 === 0) ? ' </tr>' . PHP_EOL : null;
}
echo '</table>';
它吐了出来:
<table width="100%" cellpadding="10" cellspacing="5">
<tr>
<td width="25%" align="center" valign="middle"><a href="http://www.adp.com/" target="_blank"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/ADP_logo_tag_R_rgb 4-11-13.jpg" alt="ADP" title="ADP" style="max-height:85px;" /></a></td>
</tr>
<td width="25%" align="center" valign="middle"><a href="http://ascensus.com/RetirementPlanSolutions/index.htm" target="_blank"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/Ascensus - color.jpg" alt="Ascensus" title="Ascensus" style="max-height:85px;" /></a></td>
<td width="25%" align="center" valign="middle"><a href="http://www.getbridgepoint.com/" target="_blank"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/Bridgepoint 2012.JPG" alt="Bridgepoint" title="Bridgepoint" style="max-height:85px;" /></a></td>
<td width="25%" align="center" valign="middle"><a href="http://www.brightscope.com/" target="_blank"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/BrightScope_Logo JPEG 10-10-12 approved.jpg" alt="BrightScope" title="BrightScope" style="max-height:85px;" /></a></td>
<tr>
<td width="25%" align="center" valign="middle"><a href="http://www.corporateinsight.com/" target="_blank"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/Corporate Insight Logo JPEG 9-26-12.JPG" alt="Corporate Insight" title="Corporate Insight" style="max-height:85px;" /></a></td>
</tr>
<td width="25%" align="center" valign="middle"><a href="http://www.guardianlife.com/" target="_blank"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/Guardian Logo from 2011 OK.JPG" alt="Guardian" title="Guardian" style="max-height:85px;" /></a></td>
<td width="25%" align="center" valign="middle"><a href="http://www.infosysbpo.com" target="_blank"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/Infosys McCamish_natural_vert_nt jpeg.JPG" alt="Infosys McCamish" title="Infosys McCamish" style="max-height:85px;" /></a></td>
<td width="25%" align="center" valign="middle"><a href="http://ing.us/" target="_blank"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/INGC300.JPG" alt="ING" title="ING" style="max-height:85px;" /></a></td>
<tr>
<td width="25%" align="center" valign="middle"><a href="https://www.janus.com/" target="_blank"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/JANUS logoJPEG created 9-20-12.jpg" alt="Janus Capital Group" title="Janus Capital Group" style="max-height:85px;" /></a></td>
</tr>
<td width="25%" align="center" valign="middle"><a href="http://www.jpmorgan.com/pages/jpmorgan" target="_blank"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/JP Morgan Logo for infotree.JPG" alt="JP Morgan" title="JP Morgan" style="max-height:85px;" /></a></td>
<td width="25%" align="center" valign="middle"><a href="http://www.newkirk.com/" target="_blank"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/Newkirk a DST Co 4-23-13.JPG" alt="Newkirk" title="Newkirk" style="max-height:85px;" /></a></td>
<td width="25%" align="center" valign="middle"><a href="http://www.oculuspartners.com/" target="_blank"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/Oculus_logo_v4-vert.jpg" alt="Oculus" title="Oculus" style="max-height:85px;" /></a></td>
<tr>
<td width="25%" align="center" valign="middle"><a href="http://us.pioneerinvestments.com" target="_blank"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/Pioneer Investments Jpeg ogo.JPG" alt="Pioneer Investments" title="Pioneer Investments" style="max-height:85px;" /></a></td>
</tr>
<td width="25%" align="center" valign="middle"><a href="http://www.processunity.com/" target="_blank"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/ProcessUnity logo JPEG created 9-20-12.jpg" alt="ProcessUnity" title="ProcessUnity" style="max-height:85px;" /></a></td>
<td width="25%" align="center" valign="middle"><a href="http://www.prudential.com/view/page/public" target="_blank"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/Prudential Blue Gray for Lanyards.JPG" alt="Prudential" title="Prudential" style="max-height:85px;" /></a></td>
<td width="25%" align="center" valign="middle"><a href="http://www.rrdonnelley.com" target="_blank"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/RR Donnelley Logo for Mints.JPG" alt="RR Donnelley" title="RR Donnelley" style="max-height:85px;" /></a></td>
<tr>
<td width="25%" align="center" valign="middle"><a href="http://fc.standardandpoors.com/sites/client/us/crpsite/" target="_blank"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/sp_capitaliq_fc_logo.jpg" alt="S&P Capital IQ" title="S&P Capital IQ" style="max-height:85px;" /></a></td>
</tr>
</table>