sql >> Databasteknik >  >> RDS >> Mysql

Visa mysql-data i formaterad tabell

Är det så enkelt som att flytta de sista 3 raderna som stänger det yttre bordet utanför while-slingan?

<?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>";
?>


  1. php skickar inte vidare variabler

  2. SQL Server Failover Cluster Installation -3

  3. Ta bort sista kommatecken eller förhindra att det skrivs ut överhuvudtaget MySQL/PHP

  4. autoslutförande visar alla poster, gör ingen sökning