我收到错误,并且使用以下代码返回了错误的值。
$data = $member->data();
$member1 = myId(); //Id is 8
$member2 = $data->id; //Id is 4
$query = mysql_query("
SELECT COUNT(`id`)
FROM `friends`
WHERE `member_one` = $member1
AND `member_two` = $member2
");
$friendship = (mysql_result($query, 0) == 1) ? true : false;
if($friendship):
//If we're friends
echo("Friends");
else:
//If we're not friends
echo("Not Friends");
endif;
正在返回的错误是
mysql_result()期望参数1为资源,布尔值为
结果总是错误的,尽管数据库中存在条目并且在SQL中运行相同的查询,任何想法。
答案 0 :(得分:0)
使用此:
$ data = $ member-> data(); $ member1 = myId(); // Id是8 $ member2 = $ data-> id; // Id是4 $ query = mysql_query(" SELECT COUNT(
id
) 来自friends
WHEREmember_one
= $ member1 ANDmember_two
= $ member2 &#34); $ result = mysql_feth_row($ query); $ all_result = $ result [0];if($ all_result === 1){echo" Friends&#34 ;; } else {echo" Not Friends&#34 ;; }