我有一个表,其中使用内部联接sql语句从两个表中收集会议列表。我现在遇到一个问题,它是使用meeting_id primary(在会议桌中)按顺序降序排序的。外键(在房间表中)。
<?php
$result = mysql_query("SELECT * FROM Meetings INNER JOIN Rooms ON Meetings.meeting_id = Rooms.meeting_id ORDER BY meeting_id")
or die(mysql_error());
if (mysql_num_rows($result) == 0) {
echo '<h2>There Arent Any Meetings Setup Yet</h2>';
} else {
while($info = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td><br/>" .'Title: '. $info['title']." </td>";
echo "<td><br/>" .'Chairman: '. $info['chairperson']. "</td>";
echo "<td><br/>" .'Secretary: '. $info['secretary']."</td>";
echo "<td><br/>" .'Terms Of Reference: '. $info['tof']. "</td>";
echo "<td><br/>" .'Occurances: '. $info['occurances']. "</td>";
echo "<td><br/>" .'Room: '. $info['room']. "</td>";
echo "<td><br/>" .'Date: '. $info['date']. "</td>";
echo "<td><br/>" .'Time: '. $info['time']. "</td>";
echo "<hr>";
}
}
echo "</tr>";
echo "</table>";
?>
我收到以下错误消息:
'order'idate'id'在order order子句中是不明确的'
我的表格如下:
会议:meeting_id,职称,主席,秘书,出现
房间:room_id,房间,日期,时间,meeting_id
答案 0 :(得分:2)
正如消息所说,这是模棱两可的; Rooms
和Messages
都有meeting_id
,而SQL不知道您已加入它们。只需指定一个或另一个:
$result =
mysql_query("SELECT * FROM Meetings
INNER JOIN Rooms ON Meetings.meeting_id = Rooms.meeting_id
ORDER BY Rooms.meeting_id")