I'm making a script where the user is presented with a list of records, and can check off specific ones to be printed. Each checkbox element has name="to_print[]", so basically I get an array consisting of the IDs of the rows I need to print. This array could potentially be pretty long.
What I'm wondering about is the best way to actually get these records from the database. The way I see it there are two ways: I could loop through the to_print array and query for each ID separately. However as I said, that might mean a LOT of queries, which would lead to unnacceptable performance. The only other way I can think of is to put together one massive query with a lot of ORs, like so:
SELECT * FROM table WHERE id = 2 OR id = 20 OR id = 12 OR id = 43 ... etc.
This way I'd only have to use one query, but it seems clumsy and it might be very resource intensive as well. Can anyone think of a better way to pull this off?