I have an array that was an 'explode' from an sql query, and i want in another query, search for an field called "id" by each value of the exploded array(it can be 1 value or 17) and get the field "name" associated to the id, and so create another array to print or a string separeted by ', '

I think i have to use foreach, but i really don't know how.

Can somebody help me please(giving me an example or something)?

PS:Sorry for the bad English but even in my orginal language i can't explain what i want :icon_cheesygrin:

Recommended Answers

All 3 Replies

Member Avatar for diafol

Use the 'IN' MySQL keyword to search for multiple values on ID.

SELECT fieldname FROM tablename WHERE id IN (7,6,12,19);

Use the 'IN' MySQL keyword to search for multiple values on ID.

SELECT fieldname FROM tablename WHERE id IN (7,6,12,19);

The problem is that i need to do that in a php page and the data that i have to search is coming from another sql query.

i need to do two querys to print what i want.

Thanks for the help anyway.

Member Avatar for diafol

Not usually, you can probably get it done using a JOIN of some kind - usually an INNER JOIN.

SELECT table1.fieldnameA, table2.fieldnameX FROM table1 INNER JOIN table2 ON table1.fieldnameZ = table2.fieldnameZ WHERE table1.fieldnameH = 'something'
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.