1

我试图在我的网站主页上打印出一张水平表格,其中包括一张汽车图片,然后在汽车的品牌、型号和价格下方。

这大致是我所做的:

<?php 
$List = "";
$sql = mysql_query("SELECT * FROM Car ORDER BY listed DESC LIMIT 5");

$Count = mysql_num_rows($sql);
if ($Count > 0) {
    while($row = mysql_fetch_array($sql)){
        $id = $row["id"];
        $make = $row["make"];
        $model = $row["model"];
        $price = $row["price"];

        $List .= '<table width="100%" border="0" cellspacing="0" cellpadding="6">
        <tr>
        <td width="20%" valign="top"><a href="/motors/cars.php?id=' . $id . '"><img style="border:#666 1px solid;"
        src="/../../motors-' . $id . '.jpg" alt="' . $status . ' ' . $title . '" width="100" height="80" border="1" /></a></td>
        </tr>

        <tr>
        <td width="80%" valign="top" align="left"><font face="Arial" color="#000080"><B>
        ' . $make . ' ' . $model . '</B></font><br />' . $price . '

        <a href="/motors/cars.php?id=' . $id . '">view car details</a></align></td>
        </tr>
        </table>';
    }
} else {
    $List = "No cars at present";
}
mysql_close();
?>

谁能帮我对这段代码进行排序以水平打印出来?非常感谢!

4

1 回答 1

0

图片的src很可能是错误的,/../../motors...仍然是/motors...

您可以将图像移动到您的 webapps/motors/images文件夹并将 src 设置为/motors/images/motors...

您创建的表必须嵌套在另一个表中。

<table>
    <tr>
        <td>
            <table of a car>
        </td>
       <td>
            <table of a car>
        </td>
        <td>
            <table of a car>
        </td>
        .... etc.
    </tr>
</table>

每隔几辆车发出一个 tr 来换行是有意义的。

汽车表是您在 $List 中收集的 html。

于 2015-04-11T08:16:51.833 回答