我有一张members
表和一张venues
表。
我目前有这个选择声明:
SELECT VenueName, VenueID
FROM Venue
WHERE active='Y'
ORDER BY VenueName
此语句的结果用于填充包含场地名称的下拉列表,该列表有效。我称之为“ORIGINAL SELECT”。
我想更改此内容,以便下拉列表仅显示链接到该成员的地点名称:
SELECT Venue.VenueName, Venue.VenueID, members.id, members.venueid
FROM Venue, members
WHERE Venue.VenueID = members.venueid
AND members.id='$userid'
这也有效。我称之为“新选择”。
我有两个superadmins members.venueid
是all
而不是地址ID号,所以我想创建一个语句来运行NEW SELECT else if members.id='all'
然后运行ORIGINAL SELECT
有人能指出我正确的方向吗?我尝试过各种各样的事情。
答案 0 :(得分:1)
您可以尝试类似以下内容:
SELECT Venue.VenueName, Venue.VenueID
FROM Venue, members
WHERE
(
Venue.VenueID = members.venueid
AND $userid <> 'all'
AND members.id = 'all'
)
OR
(
Venue.VenueID = members.id
AND $userid = 'all'
AND members.id = 'all'
)
答案 1 :(得分:1)
谢谢@Chris你指出了我正确的方向,下面是我工作的最终版本:
SELECT DISTINCT Venue.VenueName, Venue.VenueID
FROM Venue, members
WHERE (
'$userid' = 'all'
AND active = 'Y'
)
OR (
Venue.VenueID = members.venueid
AND members.id = '$userid'
)
ORDER BY VenueName