2017-03-09 91 views
0

ID我有一個用戶表如下獲取陣列

TABLE USERS 
user_id  user_name  user_rooms 
1   PAUL   serialized and base64_encoded data (1, 2, 4, 5, 6, 7, 8, 9, 10) 
2   JOHNL   serialized and base64_encoded data (1, 2, 3) 
3   MARK   serialized and base64_encoded data (3) 

我需要創建從該表數組USER_ID至極訪問的房間,在此示例中到室溫3:

Array ([0] => 2, [1] => 3) 

查詢(即將切換至的mysqli)爲:

$result = mysql_query("SELECT user_id, user_rooms FROM table_users"); 
$rooms = Array(); 

while ($row = mysql_fetch_assoc($result)) { 
     $user_room[] = unserialize(base64_decode($row['user_rooms'])); 
} 

$rooms返回房間數組,我想獲得與user_id數組

任何幫助嗎?

+5

爲什麼'user_rooms'存儲呀? –

+1

切換到'mysqli'是個好主意,但更好的是轉向[PDO](http://php.net/manual/en/book.pdo.php)。 – tadman

+0

你究竟在這裏問什麼?難道你不能只是''user_id [] = $ row ['user_id']',就像你使用'user_rooms'一樣嗎? –

回答

0

您可以使用此代碼:

$data=array(); 
while ($row = mysql_fetch_assoc($result)) { 
     $data[$row['user_id']] = $row['user_rooms']; 
} 

訪問,你可以像這樣訪問:

echo "$data[index]"; 
+0

這不是他想要做的。 –

+0

好的,我試過的任何方式 – Adelov