我目前正在使用搜索模块,用户可以从下拉菜单的数据库中选择汽车品牌,然后还可以在单独的下拉框中选择型号和汽车类型。
我的问题是,如何使下拉框中的左联接使用数据成为可能?
到目前为止,这是我的代码,仅供参考:
//Connect to our MySQL database using the PDO extension.
$pdo = new PDO('mysql:host=localhost;dbname=test', 'root', '');
//Our select statement. This will retrieve the data that we want.
$sql = "SELECT brands.BrandID, brands.Brands, models.ModelID, models.Models, type.TypeID, type.Type
FROM onderdelen
LEFT JOIN brands ON brands.Merknaam = onderdelen.Merknaam
LEFT JOIN models ON models.Merknaam = onderdelen.Merknaam
LEFT JOIN type ON type.Merknaam = onderdelen.Merknaam";
//Prepare the select statement.
$stmt = $pdo->prepare($sql);
//Execute the statement.
$stmt->execute();
//Retrieve the rows using fetchAll.
$cars = $stmt->fetchAll();
?>