PHP でデータベースからデータを取得し、Web サイトに表示したいと考えています。
このコードは正しく機能しません。データベースに Chevy のすべての車を表示したいと考えています。
<?php
$db = mysqli_connect("localhost","myusername",
"mypassword","database");
if (mysqli_connect_errno()) {
echo("Could not connect" .
mysqli_connect_error($db) . "</p>");
exit(" ");
}
$result = mysqli_query($query);
if(!$result){
echo "<p> Could not retrieve at this time, please come back soon</p>" .
mysqli_error($dv);
}
$data = mysql_query("SELECT * FROM cars where carType = 'Chevy' AND active = 1")
or die(mysql_error());
echo"<table border cellpadding=3>";
while($row= mysql_fetch_array( $data ))
{
echo"<tr>";
echo"<th>Name:</th> <td>".$row['name'] . "</td> ";
echo"<th>ImagePath:</th> <td>".$row['imagePath'] . " </td></tr>";
echo"<th>Description:</th> <td>".$row['description'] . "</td> ";
echo"<th>Price:</th> <td>".$row['Price'] . " </td></tr>";
}
echo"</table>";
?>
PHP を使用してデータベースからデータを取得するにはどうすればよいですか?