我有一个用户表,如下所示
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 创建此表中的数组,并且可以访问房间,在本例中为ROOM 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获取数组
任何帮助?
答案 0 :(得分:0)
您可以使用此代码:
$data=array();
while ( $row = mysql_fetch_assoc($result) ) {
$data[$row['user_id']] = $row['user_rooms'];
}
访问权限,您可以这样访问:
echo "$data[index]";