Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在格式化表中显示mysql数据_Php_Mysql - Fatal编程技术网

Php 在格式化表中显示mysql数据

Php 在格式化表中显示mysql数据,php,mysql,Php,Mysql,我正在从数据库中检索数据并显示在表中。我希望桌子是4 x 3的布局。数据检索很好,是布局不起作用。这是我的密码: <?php error_reporting(E_ALL); ini_set('display_errors', '1'); $db = new mysqli('localhost', 'root', '', 'ezwayautos'); if($db->connect_errno > 0){ die('Unable to connect to datab

我正在从数据库中检索数据并显示在表中。我希望桌子是4 x 3的布局。数据检索很好,是布局不起作用。这是我的密码:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

$db = new mysqli('localhost', 'root', '', 'ezwayautos');

if($db->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
}
$sql = "SELECT * FROM vehicles ORDER BY RAND() LIMIT 12";

if(!$result = $db->query($sql)){
    die('There was an error running the query [' . $db->error . ']');
}
    echo "<table>";
while($row = $result->fetch_assoc())
{
    echo "<tr>";
    echo "<td height='160' valign='top' class='featured'>";
    echo "<div class='Image-Thumbnail'>";
    echo "<a href=''>";
    echo "<img src='".$row['image']."' width='160' height='54'>";
    echo "</a>";
    echo "</div> <a href=''>" .$row['vehicle_name']. "</a>";
    echo "</td>";
    echo "</tr>";
}
    echo "</table>";
?>

它是否像将关闭外部表的最后3行移到while循环外那样简单

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

$db = new mysqli('localhost', 'root', '', 'ezwayautos');

if($db->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
}
$sql = "SELECT * FROM vehicles ORDER BY RAND() LIMIT 12";

if(!$result = $db->query($sql)){
    die('There was an error running the query [' . $db->error . ']');
}
echo "<table>";
echo "<tr>";
echo "<td>";
while($row = $result->fetch_assoc())
{
    echo "<table border='0' cellpadding='0' cellspacing='0'>";
    echo "<tr>";
    echo "<td height='160' valign='top' class='featured'>";
    echo "<div class='Image-Thumbnail'>";
    echo "<a href='inventory/view/7995179/2005-Volvo-XC90-4dr-2.html'>";
    echo "<img src='".$row['image']."' width='160' height='54' alt='".$row['vehicle_name']."'>";
    echo "</a>";
    echo "</div> <a href='inventory/view/7995179/2005-Volvo-XC90-4dr-2.html'>" .$row['vehicle_name']. "</a>";
    echo "</td>";
    echo "</tr>";
    echo "</table>";
}
echo "</td>";
echo "</tr>";
echo "</table>";
?>

表格生成不正确。我认为您不是要在另一个表中创建一个表,因此我认为这是您应该做的:

echo "<table>";
while($row = $result->fetch_assoc())
{
    echo "<tr>";
    echo "<td height='160' valign='top' class='featured'>";
    echo "<div class='Image-Thumbnail'>";
    echo "<a href='inventory/view/7995179/2005-Volvo-XC90-4dr-2.html'>";
    echo "<img src='".$row['image']."' width='160' height='54' alt='".$row['vehicle_name']."'>";
    echo "</a>";
    echo "</div> <a href='inventory/view/7995179/2005-Volvo-XC90-4dr-2.html'>" .$row['vehicle_name']. "</a>";
    echo "</td>";
    echo "</tr>";
}
echo "</table>";
echo”“;
而($row=$result->fetch_assoc())
{
回声“;
回声“;
回声“;
回声“;
回声“;
回声“;
回声“;
}
回声“;

必须创建一次表,然后为每条记录创建一行。

循环中的最后3行应该在it@Dagon你一直在几秒钟之内就把我揍得体无完肤,但我的借口是,我必须格式化一些code@RiggsFolly幸运的是,我喜欢打得很好。我想你必须给我们展示一个你是什么样的人的例子,然后我们需要知道什么进入了什么细胞。对于这样的问题,你应该准确。“what”是您的查询中的哪些行等。相应地编辑您的问题。如果有什么好处@Dagon,我对您的评论投了赞成票,但随后将其拿走并交给Smokey。他指的是BOSCH。他是个很有活力的人。我们给他起名叫斯巴基我相信斯巴基不会介意;-)你不是斯巴克人吗@达戈尼已经尝试了这两个建议,但我仍然让显示器从上到下显示,而不是4 x 3,表示4个单元格宽3个单元格低