I am trying to use a single select to get the first and last name for a group of users.
Here are the two approaches (Test 1 & Test 2) I tried to get the data.
Both approach gave the same error.
Error: Unknown column 'norma' in 'where clause'
What is wrong with my approch(s)?
<?
//open connection
$mysqli = db_connect();
db_select($mysqli, $db_id);
//initiate array
$per_list = array();
$per = array();
//assign values of user name to array
$per_list[] = "norma";
$per_list[] = "alex";
$per_list[] = "sean";
/**Test 1**/
$query = "SELECT userid, first_name, last_name
FROM users
WHERE username IN (".implode(',',$per_list).")";
$result = mysqli_query ($mysqli, $query) or die("Error: ".mysqli_error($mysqli));
while($row = mysqli_fetch_array($result))
{
$per[] = $row;
}
/**Test 2**/
$per_list = implode(", ", $per_list);
$query = "SELECT userid, first_name, last_name
FROM users
WHERE username IN ($per_list)";
$result = mysqli_query ($mysqli, $query) or die("Error: ".mysqli_error($mysqli));
while($row = mysqli_fetch_array($result))
{
$per[] = $row;
}
?>