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

  • Home
  • SEARCH
  • 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 7488111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:44:38+00:00 2026-05-29T14:44:38+00:00

I have asked a question about how to retrieve data from different tables in

  • 0

I have asked a question about how to retrieve data from different tables in sql How to get data from 4 tables in 1 sql query?

When I run the query for my sample data I get 3 rows, anyway being many-to-many relationship between courses and categories I will always get more rows for same course.

My question is how do I handle this data in PHP? I get an array and what I want would be something like:

Array ( 
  [0] => stdClass Object ( 
      [name] => course name 
      [tutor] => tutor name 
      [categories] => Array ( categories here ) 
);

Should I just fetch the data from the categories in a foreach loop after I fetch a course? That would mean bad performance for large amount of data.

  • 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-05-29T14:44:40+00:00Added an answer on May 29, 2026 at 2:44 pm

    Should I just fetch the data from the categories in a foreach loop after I fetch a course? That would mean bad performance for large amount of data.

    I think that depends on what you will do with the data. If it’s just to show to user, i think it’s a good idea paginate the results.

    But if you really need to fecth all data in one query and store this in one big array, you can do something like this:

    $last_id = -1;
    for( $x=0; $x < count($myArray); $x++ ) {
      if( $last_id != $myArray[$x]['id'] ) {
        //course changed, do something!
      } 
      //do more stuff...
      $last_id = $myArray[$x]['id'];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I have asked a question about what I should use to create self-contained
I have been asked to post a new question about how to correctly sort
Ok, I have asked a few questions about different facets of trying to accomplish
I have asked a question on SuperUser about updating Ruby version in Google SketchUp
I have asked this question here about a Python command that fetches a URL
I have asked this question about using the a Linq method that returns one
I asked a question about C-type sizes which I get a pretty good answer
I have asked this question in a different post here on SO: How can
I have asked a question about how to avoiding to write the html in
I've previously asked a question about an issue I have been experiencing with CSharpOptParse

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.