如何限制HTML中的列数量

时间:2014-03-02 20:36:06

标签: php html mysql sql

如何限制HTML表格可以显示的列数量。数据从SQL表中拉出,然后显示在表格中,但我只希望表格显示为6行,然后开始一个新的相反它将无限量添加到单行中我该如何解决这个问题呢?

<?php
$con=mysqli_connect("localhost","Username","Password","Database");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,"SELECT * FROM menus");
echo "<table width='400'>";
echo "<tr>";
while($row = mysqli_fetch_array($result))
  {
echo'<td>';

?>

<a href="<?php echo $row['link']; ?>" class="tip" alt="<?php echo $row['game']; ?>">
<img src="<?php echo $row['picture']; ?>" alt="" width="150" height="120" class="fade" />
</td>

<?php
}
mysqli_close($con);
?>
</table>

1 个答案:

答案 0 :(得分:0)

$cols = 0;
echo '<table><tr>';
while($row = fetch()) {
  $cols++;
  if ($cols >= 6) {
     echo '</tr><tr>';
     $cols = 0;
  }
  echo '<td> ...</td>';
}
echo '</tr></table>';