使用PHP MySQL打印包含图像的水平表

时间:2015-04-11 08:12:32

标签: php html mysql dynamic-tables

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

这里大概是我所做的:

<?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();
?>

任何人都可以帮助我对此代码进行排序以水平打印吗? 非常感谢!

1 个答案:

答案 0 :(得分: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。