<?php
include 'includes/db.php';
echo "<h2>Brand Matching Check</h2>";
// Get unique brands from cars table
echo "<h3>Brands in Cars Table:</h3>";
$cars_brands = $conn->query("SELECT DISTINCT brand FROM cars WHERE brand IS NOT NULL AND brand != '' ORDER BY brand");
$cars_brand_list = [];
while($row = $cars_brands->fetch_assoc()) {
$cars_brand_list[] = $row['brand'];
echo "- " . htmlspecialchars($row['brand']) . "<br>";
}
echo "<h3>Brands in Brands Table:</h3>";
$brands_table = $conn->query("SELECT name FROM brands ORDER BY name");
$brands_table_list = [];
while($row = $brands_table->fetch_assoc()) {
$brands_table_list[] = $row['name'];
echo "- " . htmlspecialchars($row['name']) . "<br>";
}
echo "<h3>Matching Analysis:</h3>";
foreach($cars_brand_list as $car_brand) {
if (in_array($car_brand, $brands_table_list)) {
echo "<span style='color: green;'>✓ MATCH: " . htmlspecialchars($car_brand) . "</span><br>";
} else {
echo "<span style='color: red;'>✗ NO MATCH: " . htmlspecialchars($car_brand) . "</span><br>";
}
}
echo "<h3>Test JOIN with specific brand:</h3>";
if (!empty($cars_brand_list)) {
$test_brand = $cars_brand_list[0];
$stmt = $conn->prepare("SELECT c.name, c.brand, b.logo FROM cars c LEFT JOIN brands b ON c.brand = b.name WHERE c.brand = ? LIMIT 1");
$stmt->bind_param("s", $test_brand);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
echo "Car: " . htmlspecialchars($row['name']) . "<br>";
echo "Brand: " . htmlspecialchars($row['brand']) . "<br>";
echo "Logo: " . htmlspecialchars($row['logo']) . "<br>";
if ($row['logo']) {
echo "<img src='uploads/brands/" . htmlspecialchars($row['logo']) . "' style='width: 50px; height: 50px; object-fit: contain;'><br>";
}
}
$stmt->close();
}
$conn->close();
?>