我有2个表,我必须使用where =“其他表中的此值”来获取一个表的数据
users_info and users_frnds
users_info look like this
name image presently id
somename somimage studying 2
somename somimage studying 3
users_frnds table looks like this
userid friendid
1 2
1 3
$query = "SELECT * FROM users_info WHERE users_info.id =
users_frnds.friendid";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo $row['name']. " - ". $row['image'];
echo "<br />";
但它似乎不适用于此。我希望将所有数据一次性存入我的阵列。 谁能帮助我呢。谢谢
它抛出了我的错误
Unknown column 'users_frnds.friendid' in 'where clause'
答案 0 :(得分:1)
您需要加入,例如:
SELECT specifyfields
FROM users_friends
INNER JOIN users_info ON users_info.id=users_friends.friendid
然后你将获得访问权限,尝试永远不要在WHERE子句中连接表,因为这可能会创建非常难以理解的查询。