[SOLVED] What command to fetch primary key matches stored in

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
voltrader
Forum Contributor
Posts: 223
Joined: Wed Jul 07, 2004 12:44 pm
Location: SF Bay Area

What command to fetch primary key matches stored in array?

Post by voltrader »

I have a search function that returns pk results in an array.

Is there a command to fetch those records from mysql in one go?

Or do I have to loop through the array and fetch individual records?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

you can use IN function:

Code: Select all

$query = 'select * from some_table where pk_column in(' . implode(',', $pk_array) . ')';
// then execute the query and fetch rows as usual...
User avatar
voltrader
Forum Contributor
Posts: 223
Joined: Wed Jul 07, 2004 12:44 pm
Location: SF Bay Area

Post by voltrader »

thanks -- much appreciated!
Post Reply