Skip to content
Advertisement

How to fetch values for every id present in array using loop

I have an array with following values:

JavaScript

and a table 'orderdetails' in database with order_title and order_id columns.

What I want is to fetch order_title of every order using order_id in a loop. Can anyone help?

What I know is:

JavaScript

but this will make query run multiple times, any better solution?

UPDATE:

When I try to use IN(), values are getting inserted like this:

JavaScript

but what problem is here, query is only returning the value for first element in array that is 2

the solution needs to get applied is IN('2','8','10','12') all the values should be in a single quote, but I don’t know how to achieve that.

Advertisement

Answer

You can use WHERE IN :

JavaScript

Query :

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement