Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8494417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:17:36+00:00 2026-06-10T23:17:36+00:00

I have three tables, Entries , Tags , Entry_Tag_Link I have my query which

  • 0

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)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T23:17:38+00:00Added an answer on June 10, 2026 at 11:17 pm

    I assume your blog entry id is blog_entry_id…

    Request :

    SELECT b.title, t.entry_id, t.name, l.tag_id 
    FROM blog_entries b
    JOIN blog_tags t on t.entry_id = b.blog_entry_id
    JOIN blog_entries_tags_link l on t.id = l.tag_id
    ORDER BY b.date DESC, t.name ASC
    

    PHP :

    $result = array();
    foreach ($entries as $entry) {
    
        // Creates a new blog entry on the $result array
        if (!isset($result[ $entry['entry_id'] ])) {
            $blog_entry = array();
            $blog_entry['id'] = $entry['entry_id'];
            $blog_entry['title'] = $entry['title'];
            $blog_entry['tags'] = array();
            $result[ $entry['entry_id'] ] = $entry;
        }
    
        // Add a new tag
        $tag = array();
        $tag['id'] = $entry['tag_id'];
        $tag['name'] = $entry['name'];
        $result[ $entry['entry_id'] ]['tags'][] = $tag;
    
    }
    

    You may note that you never use blog_entry_tags_link (I am using it just because I do not know your column names).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables(entries and tags) with a many-to-many linking table. Right now, I'm
I have three tables that I would like to query: Streams, Entries, and FieldInstances.
I have this query which grabs the max date record for three different tables.
I have three tables of data: table: cars [10,000 rows] table: planes [2,000 rows]
I have three tables Author, Book and AuthorBook. AuthorBook table only contains two foreign
I have three tables in oracle db as newitems, itemdetails, ticketitems table. Some dummy
I have three tables, table one (tableA) containing users data like name and email,
I have three tables, which are each 1:n. An entry in table1 has n
I have three tables: unmatched_purchases table: unmatched_purchases_id --primary key purchases_id --foreign key to events
I have a common database joining situation involving three tables. One table, A, is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.