對於一個應用程序,我試圖計算總共的朋友數。我想用一個函數做到這一點,但它不會返回任何東西。它告訴我:使用sql計算php的行數
警告:mysqli_query()預計至少2個參數,1給出
但我只需要一個參數。我認爲我完全錯了。
這是函數:
public function GetTotalOfFriends($user_id){
$db = new Db();
$select = "SELECT COUNT FROM friendship WHERE (friendship_recipient_id ='" . $user_id ."' OR friendship_applicant_id = '" . $user_id . "') AND friendship_status = 'accepted'";
$result = $db->conn->query($select);
$row = mysqli_query($result);
$total = $row[0];
echo $total;
我試圖把它打印出來這樣:
$friend = new Friendship;
$numberoffriends = $friend->GetTotalOfFriends($user_id);
<?php echo $numberoffriends; ?>
看看http://www.php.net/manual/en/mysqli.query.php 你需要通過一個連接和您的查詢不是你的結果 –