0
我在從我的DBcon查詢中獲取數組時遇到問題。從數據庫查詢獲取和添加數組時遇到的問題
我的表是這樣的:
tbl_current_userconnections:
user_id | connection_id
---------------------------
1 | 5
1 | 6
tbl_former_userconnections:
user_id | connection_id
---------------------------
|
|
可以說活躍用戶與ID的用戶= 1這個用戶莫名其妙地叫我的PHP-碼。通過下面的代碼發佈,我預計$MessengerString
的結果爲5,6
。但事實證明,結果是5,5
。我絕對不明白爲什麼。有人可以指出我的代碼中有什麼問題嗎?
在此先感謝!
$curContacts = $DBcon->query("SELECT connection_id FROM tbl_current_userconnections WHERE user_id=".$_SESSION['userSession']);
$count1=$curContacts->num_rows;
$forContacts = $DBcon->query("SELECT connection_id FROM tbl_former_userconnections WHERE user_id=".$_SESSION['userSession']);
$count2=$forContacts->num_rows;
if ($count1!==0 && $count2!==0) {
$curContacts=$curContacts->fetch_array();
$forContacts=$forContacts->fetch_array();
$MessengerArray = array_merge($curContacts, $forContacts);
} else if ($count1==0 && $count2!==0) {
$MessengerArray = $forContacts->fetch_array();
//this will be the case:
} else if ($count1!==0 && $count2==0) {
$MessengerArray = $curContacts->fetch_array();
} else {
$MessengerArray = '';
}
$MessengerString = implode(',',$MessengerArray);