我的 sql 数据库中有两个关联的表。一个是名为“airports”的机场列表,另一个是名为“airport_profiles”的航空公司列表。后者是我想关注的。我通过 airport_id 行将航空公司与机场相关联。即身份证号码参考机场。我当前的 PDO 查询是:if(isset($_GET['airport'])) {if ($_GET['airport'] == 1) { $airportQuery = "SELECT * FROM airport_profiles"; $airport = $db->prepare($airportQuery); $airport->execute();}else { $airportQuery = "SELECT * FROM airport_profiles WHERE airport_id = :airport_id"; $airport = $db->prepare($airportQuery); $airport->execute(['airport_id' => $_GET['airport']]);} $selectedAirport = $airport->fetchAll(); foreach ($selectedAirport as $profile) { if ($profile['id'] == 1) continue;我试过插入 $profile = explode(';', $airport_id); 但这根本不起作用。如果我错了,请纠正我,但根据我的理解,为了将不止一家航空公司与一个机场相关联,我需要添加一个爆炸“;” 到查询,以便我的 airport_id 的分号分隔。任何建议都将受到极大欢迎。提前谢谢了。
1 回答
青春有我
TA贡献1784条经验 获得超8个赞
查询更改为以下内容:
if(isset($_GET['airport'])) {
if ($_GET['airport'] == 1) {
$airportQuery = "SELECT * FROM airport_profiles GROUP BY airline_name";
$airport = $db->prepare($airportQuery);
$airport->execute();
}
else {
$airportQuery = "SELECT * FROM airport_profiles WHERE airport_id = :airport_id";
$airport = $db->prepare($airportQuery);
$airport->execute(['airport_id' => $_GET['airport']]);
}
$selectedAirport = $airport->fetchAll();
foreach ($selectedAirport as $profile) {
if ($profile['id'] == 1) continue;
- 1 回答
- 0 关注
- 109 浏览
添加回答
举报
0/150
提交
取消