开发者

Is my MySQL query right? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
开发者_如何转开发

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 9 years ago.

Improve this question

I have a error with a php script and I am not quite sure that my join query is right?

$sql15 = mysql_query("select  userid, Reciver, Sender , proimg from Friends JOIN users ON(Reciver ='$fullname' or Sender ='$fullname') where accepted = 2") or die("ERROR Please refresh the page and try again"); 
$Fri = mysql_num_rows($sql15);

and this is the other one which I think is the problem

$sql12 =  mysql_query("select * from Friends where (Reciver = '$fullname' or Sender = '$fullname')") or die("ERROR Please refresh the page and try again"); 
$Friends = mysql_num_rows($sql12);

Question: What is wrong with my mysql querys?


No, your JOIN syntax is not right. JOIN should be used to, well, join tables. For example:

SELECT *
FROM friends
JOIN users ON friends.user_id = users.id

This would join the table "friends" with the table "users" by comparing the columns specified.

Your current JOIN clause is comparing fields to variables -- essentially trying to use it like a WHERE clause. This won't throw an error, but it also won't do any joining.

The MySQL docs are quite good: http://dev.mysql.com/doc/refman/5.0/en/join.html You should give them a read and test your SQL either using the Workbench app or the MySQL command line. These tools will give you much better feedback than using or die... in PHP.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜