Mysql
 sql >> Database >  >> RDS >> Mysql

Visualizza i dati mysql nella tabella formattata

È semplice come spostare le ultime 3 righe che chiudono la tabella esterna al di fuori del ciclo 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>";
?>