In my database I have a table containing records with their own primary id key and a user id key. Client side, in my javascript, I have an array full of many many user ids. For each id in this array, I wish to search and select the record(s) in the table with the matching user id associated. I'm not sure if I have the best, most efficient method of doing so.
Right now, this is what I am thinking:
Semi-psuedo code:
Javascript
for each element (user id) in array:
.get( 'script.php', userid_data, function(response){
// ..do something with the row/record data of that specific user...
}
So for each user id in that array, I perform an AJAX get() request, sending that specific user id to a php script which searches the entire table for a record/row with a user id match.
PHP/MySQL (script.php)
/*..some connection code..*/
/*.. some receive code..*/
/* query code: */
"SELECT * FROM `recordTable` WHERE `userid` =" .var_containing_userid.";"
/*...some array to json encoding..*/
/* return attribute data */
However, though this is the only way I can think of, this just does not seem to be the most efficient way right now to me.
This is because, theoretically, both the array of user id's and the number of records could be infinitely many (or just a lot) in the future. I'm not sure how fast this would run if there were hundreds of IDs and an ever growing number of records in this table.
Is there a better/faster way? How large could the table of records grow before the execution of such a method becomes significantly slow? I am using PhpMyAdmin.