从DATABASE WHERE中选择

时间:2014-07-06 08:43:31

标签: php mysql select

我有2个表,membersappoint。在appoint我有members_id。这是对的吗?

$result = mysql_query ("SELECT * FROM members,appoint WHERE members_id=id ORDER BY id");
while ($row = mysql_fetch_array ($result))

这会返回此错误“Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

使用

的显式连接语法
SELECT * FROM members
INNER JOIN appoint ON members.id = appoint.members_id
ORDER BY members.id

最好在引用列时使用表名。如果两个表具有相同的列名,则DB将不知道要采用哪一个。

答案 1 :(得分:0)

你可以试试这个

SELECT m.*, a.* FROM members AS m JOIN appoint AS a ON m.members_id = a.id ORDER BY a.id ASC