MySQL:获取重复查询字段的重复数据

I am new to mySQL and PHP, so bear with me.

How can I make it so that if my query has duplicate fields, the data retrieved would have repeated data for the repeated query fields.

An example would be like:

query for id = 34, 54, 21, 21, 50 (already in the order I want them to be in)

I want the database to return

user_icon for id = 34, user_icon for id = 54, user_icon for id = 21, user_icon for id = 21, and user_icon for id = 50.

And not just one data returned for the duplicate id 21.

Here is the code I am using at the moment:

 $thumb = "SELECT thumbnail from users WHERE id IN (".$idsearch.") ORDER BY FIELD(id , ".$idsearch.")";
   $search = $con->prepare($thumb);
   $search -> execute();

   $pics = $search->fetchAll();
   foreach($pics as $pic) {
     $thumbnail[] = $pic['thumbnail'];
  }

Thank you for the help!

I am not able to think of a MYSQL query right now. But if perfomance is not of a concern, you can use some thing like

$thumb = "SELECT thumbnail from users WHERE id = ?";
$search = $con->prepare($thumb);

foreach($idsearch as $id) {
   $search->execute(array($id));
   $pics = $search->fetch(PDO::FETCH_ASSOC);
   $search->closeCursor();
   $thumbnail[] = $pic['thumbnail'];
}

PDO will compile the SQL Query and the execution will be faster than a normal sql query.

An SQL query returns every row in the table that matches the where condition. If you want to filter duplicates out, it requires you to explicitly do that (e.g., by using the distinct keyword). Since your query does not have any such special treatment, it will return duplicates if they exist, so your code is fine.