0

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:

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by diafol
0

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

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

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.

0

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'
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.