创建网格而不是表格

时间:2012-02-22 22:19:28

标签: php mysql html css

对于下表,而不是分页,我想创建一个结果网格。

所以我想回应一组10个结果,然后继续向右200像素的过程。然后在10个结果之后,继续向右200像素。

我该怎么做?

$query2 = "SELECT street1, city, state, zip, phone, website
FROM addresses
WHERE submissionid=$submissionid
ORDER BY street1 DESC";     


$result2 = mysql_query($query2);

$arr2 = array(); 

   echo "<table class=\"commentecho3\">";


    while ($row2 = mysql_fetch_array($result2)) { 

        echo '<tr>';
        echo '<td>'.strtoupper($row2["street1"]).'</td>';
        echo '</tr>';

        echo '<tr>';
        echo '<td>'.strtoupper($row2["city"]).', &nbsp;'.strtoupper($row2["state"]).'&nbsp;&nbsp;'.strtoupper($row2["zip"]).'</td>';
        echo '</tr>';

        echo '<tr>';
        echo '<td>'.strtoupper($row2["phone"]).'</td>';
        echo '</tr>';

        echo '<tr>';
        echo '<td>'.strtoupper($row2["website"]).'</td>';
        echo '</tr>';

        echo '<tr>';
        echo '<td></td>';
        echo '</tr>';

        echo '<tr>';
        echo '<td></td>';
        echo '</tr>';

    }
    echo "</table>";

1 个答案:

答案 0 :(得分:0)

是否真的有必要在那里使用表格?像Webgal建议的那样,使用浮动div可以很容易地完成: 在css中创建一个类     包含.foo {浮动:左;填充右:200像素;}

更新PHP(可以通过不同的方式完成):

$i=0;
echo('<div class="foo">');
while ($row2 = mysql_fetch_array($result2)) {
echo '<p>'.strtoupper($row2["street1"]).'</p>';
  .................................
$i++;
if ($i=10){
  echo('</div><div class="foo">');
}
}
echo('</div>');
相关问题