-4

I have 2 tables, members and appoint. In appoint i have members_id. Is that correct?

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

This returns me this error "Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given"

Any ideas?

Vyktor
  • 19,854
  • 5
  • 58
  • 94
user3808157
  • 27
  • 1
  • 1
  • 5

2 Answers2

1

Use the explicit join syntax which is

SELECT * FROM members
INNER JOIN appoint ON members.id = appoint.members_id
ORDER BY members.id

And better use the table name when refering to columns. If two tables have the same column names then the DB won'T know which one to take.

juergen d
  • 195,137
  • 36
  • 275
  • 343
  • 1
    And it will lead to `Error Code: 1052. Column 'id' in where clause is ambiguous` (original query) or `Error Code: 1052. Column 'id' in on clause is ambiguous` (explicit joins) – VMai Jul 06 '14 at 08:56
  • Good catch. Corrected that :) But not in the `on` clause but in the `order by` – juergen d Jul 06 '14 at 08:59
0

You can try this

SELECT m.*, a.* FROM members AS m JOIN appoint AS a ON m.members_id = a.id ORDER BY a.id ASC
Md. Sahadat Hossain
  • 3,162
  • 4
  • 28
  • 54