I have three tables,
Entries, Tags, Entry_Tag_Link
I have my query which goes through and pulls everything out of the Entries table
SELECT *
FROM (`blog_entries`)
ORDER BY `date` desc
I end up with an array of entries.
After that I loop through as
foreach($entries as &$entry)
$entry['tags'] => getTags($entry['id]);
The getTags function runs this query
SELECT t.*
FROM blog_tags t
JOIN blog_entries_tags_link l
ON t.id = l.tag_id
WHERE l.entry_id = {whatever id was passed}
ORDER BY t.name asc;
So I end up with an array that looks like:
Array
(
[0] => Array
(
[id] => 1
[title] => First Title
[tags] => Array
(
[0] => Array
(
[id] => 1
[name] => t1
)
[1] => Array
(
[id] => 2
[name] => t2
)
)
)
[1] => Array
(
[id] => 2
[title] => Second Title
[tags] => Array
(
[0] => Array
(
[id] => 1
[name] => t1
)
[1] => Array
(
[id] => 3
[name] => t3
)
)
)
)
So, what it means is that I end up with 201 queries if there are 200 entries,
I am wondering if there is a way to get all the data I need in one query (and then assumedly massage it into the correct format with php)?
I assume your blog entry id is blog_entry_id…
Request :
PHP :
You may note that you never use blog_entry_tags_link (I am using it just because I do not know your column names).