我试图将表格单元格的打印限制为每行 3 个。这在一个示例中有效,但当我尝试在站点的其他地方使用相同的代码时显然不起作用。这是代码:
$n=3;
echo "<table cellpadding='10' cellspacing='10' style='margin-right:-70px;'><tr>";
$users_count = count($users);
for($i=0; $i<$users_count;$i++)
{
$temp = array();
$temp = $users[$i];
echo "<td>";
echo "<div id='kitchen_box'>";
echo "<div id='kitchen_box_details'>";
echo "<h4>".$temp->fullname . "</h4><br>";
if(strcmp($temp->address, '') == 0)
echo $temp->city;
else
echo $temp->address.", ".$temp->city;
echo "</div>";
echo "<div id='kitchen_box_pic'><img id='kitchen_image' src='".$temp->profilepic."' /></div>";
echo "</div>";
echo "</td>";
if($i != 0){
if($i % $n == 0 && $i != $users_count-1){
echo "</tr><tr>";
}
else{
echo ""; //if it is the last in the loop - do not echo
}
}
}
echo "</table>";
我不明白为什么这不起作用!我非常感谢您对此事的支持:)