There is a POST request of a collection of user ids being passed into a PHP script. This collection is being compared with existing ids in 'user_table'.
This is achieved by joining an array of the ids into a string, and the resulting string of comma-separated ids is used directly in the query.
I fear that this will not scale well, and potentially be a disaster! Can anyone share some wisdom as to the conventional approach to this kind of problem?
$id_json_array = postVar('u');
$user_ids = json_decode($id_json_array);
$str_ids = join(',', $user_ids);
$result = mysql_query(
"SELECT u.user_id AS i
, u.user_name AS u
FROM user_table u
WHERE u.user_id IN ($str_ids)"
) or die (mysql_error ());
The ids array would be perhaps a couple thousand, and the 'user_table' is large (tens or hundreds of thousands, indexed, etc.)
Thanks in advance.