table: database1.comment
id | owner_id | comment
1 | 1 | some words
2 | 1 | some words
3 | 2 | some words
table: database2.users
id | display_name
1 | admin
2 | guest
I am try to join 2 tables query, here is my php code:
$result = mysql_query("SELECT * FROM database1.comment INNER JOIN database2.users ON database1.comment.owner_id=database2.users.id order by database1.comment.id DESC");
while ($row = mysql_fetch_array($result)){
echo '<li>'.$row['display_name'].': '.$row['comment'].'</li>';
}
I get a error message: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given. How to make a work code ( optimize way )
If your query is invalid (or otherwise “failed”), mysql_query() returns “false” (instead of an array).
SUGGESTIONS:
Cut/paste your SQL string into MySQL, see what’s incorrect, and fix it. And that point, your PHP should be OK.
Check your result (and gracefully handle any failures/errors) in your code:
EXAMPLE (error: no “from” clause):