如何从表中获取数组数据?

I have a tags_ids array 1,3,2 and

data in my table:

+---------+----------+
| user_id | tag_id   |
+---------+----------+
|       1 |        1 |
|       1 |        2 |
|       2 |        1 |
|       2 |        2 |
+---------+----------+

I want to get the users ids into array, but not working:

foreach ($tags_ids as $i)
    {
        if ($result = $mysqli->prepare("SELECT `user_id` FROM `mytable` WHERE `tag_id`=?"))
        {
            $result->bind_param("i",$i);
            $result->execute();
            $result->bind_result($d);
            $result->fetch();
            $result->close();
        }

        if (!in_array($d,$users_ids)) $users_ids[] = $d;
    }

My result is always 1. Whats I'm doing wrong, and can I do it in a more simple way?

you need a while loop, you can find it here for full assist:http://www.youtube.com/watch?v=hO0YOOeJrOE
be sure to watch the other video's too, very helpfull.

goodluck, PHPNoob