I have a database, and I want to get the names of multiple users in the same query by passing in an array of user_ids. Sadly, I cannot get this to work.
I have this query:
$stmt = $this->db->prepare('SELECT name FROM users WHERE user_id=?');
Where the parameter is an array:
$stmt->bind_param('i', $user_ids);
The user_ids array looks like this {1, 2}. Basically, I want to get the name of user 1 and user 2, without having to query the database more than one time.
When I have this code, I only seem to get the name of the first user, not the others:
$stmt->bind_result($name);
while ($stmt->fetch()) {
array_push($names, $name);
}
Keep in mind that I have initialized $names like this $names = array();
How could I solve this?
Any help would be appreciated!