如何使用PHP在两列中显示结果?

时间:2013-11-15 12:43:31

标签: php dreamweaver

我尝试将产品详细信息显示为2列。

目前,我的下面的PHP显示为单个列。有人可以帮忙吗?感谢

品牌A品牌B

品牌C品牌D

品牌A

品牌B

品牌C

品牌D


    <?php 
    $count = 0;

    while($record = mysql_fetch_array($results)){
    $id = $record["prod_id"];
    $brand = $record["prod_brand"];
    $name = $record ["prod_name"];
    $nameC = $record ["prod_name_c"];
    $price = $record ["prod_price"];

    if($count % 2 <> 0) {

    extract($record);

    echo '<td class="itemHotDesc" id="bfTable3" valign="top"><a href="productDetail.php?id='.$id.'"><img src="admin/img/' . $id . '.jpg" class="itemImgborder" /></td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="itemHotDesc" align="center">';
    echo $brand;
    echo '</br>';
    echo $name;
    echo '</br>';
    echo $nameC;
    echo '</br>';
    echo 'Special: US$'.$price;
    echo '</td>';
    echo '</tr>';      
    echo '<tr>';
    echo "<td>&nbsp;</td>";
    echo '</tr>';
    }
    else
    {
    echo '<td class="itemHotDesc" id="bfTable3" valign="top"><a href="productDetail.php?id='.$id.'"><img src="admin/img/' . $id . '.jpg" class="itemImgborder" /></td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="itemHotDesc" align="center">';
    echo $brand;
    echo '</br>';
    echo $name;
    echo '</br>';
    echo $nameC;
    echo '</br>';
    echo 'Speical: US$'.$price;
    echo '</td>';
    echo '</tr>';      
    echo '<tr>';
    echo "<td>&nbsp;</td>";
    echo '</tr>';
    }
    $count++;   
}

&GT?;

1 个答案:

答案 0 :(得分:0)

您的问题与PHP无关,但与HTML有关。

要拥有包含多个列的表,您需要每行拥有一个<table>元素和一个<tr>元素。在每个<tr>中,您需要为每个设置一个<td>元素。

如果每个<td>中只有一个<tr>,则不会有多个列。

以下是包含多列的表的示例:

<table>
    <tr>
        <td>This is row 1, Column 1</td>
        <td>This is row 1, Column 2</td>
        <td>This is row 1, Column 3</td>
    </tr>
    <tr>
        <td>This is row 2, Column 1</td>
        <td>This is row 2, Column 2</td>
        <td>This is row 2, Column 3</td>
    </tr>
    <tr>
        <td>This is row 3, Column 1</td>
        <td>This is row 3, Column 2</td>
        <td>This is row 3, Column 3</td>
    </tr>
</table>

这应该给你类似

的东西
-------------------------------------------------------------------------------
| This is row 1, Column 1 | This is row 1, Column 2 | This is row 1, Column 3 |
|-------------------------|-------------------------|-------------------------|
| This is row 2, Column 1 | This is row 2, Column 2 | This is row 2, Column 3 |
|-------------------------|-------------------------|-------------------------|
| This is row 3, Column 1 | This is row 3, Column 2 | This is row 2, Column 3 |
-------------------------------------------------------------------------------