Is it possible that you can make a JOIN in SQL, which is used to extract information from a database, and not to collect data in multiple queries? It would be much faster and more accurate to do this at the database level.
Depending on the structure of your database, you might use something similar to
SELECT entry_id, title, author_id FROM exp_weblog_data INNER JOIN exp_weblog_titles ON exp_weblog_data.entry_id = exp_weblog_titles.entry_id WHERE field_id_53 = "%s" AND WHERE entry_id IN ("%s")
Wikipedia has a bit for each type of connection.
Otherwise, restructuring the first array may be the best option, so this is an entry_id map for the header
So:
array( array( 'entry_id' => 1, 'title' => 'Test Entry 1', ), array( 'entry_id' => 3, 'title' => 'Test Entry 2', ), )
It would be:
array( 1 => 'Test Entry 1', 3 => 'Test Entry 2', )
This would mean that the code needed to combine arrays is simplified:
$entriesArray = array(); foreach ($entryAuthors as $authors) { $entriesArray[] = array( 'id' => $authors['entry_id'], 'title' => $entryNames[$authors['entry_id']], 'author_id' => $authors['author_id'] ); }
source share