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 6751323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:54:48+00:00 2026-05-26T12:54:48+00:00

I need to speed up an sql query. Or handle the php code better.

  • 0

I need to speed up an sql query. Or handle the php code better. Some best practice when searching a database and displaying the result in the frontend.

Basically I have three tables
– boxes, that contains records
– records, that contains songs
– song

I would like my frontend code to list something like:

Box 1
 -Record 1
  --Song 1
  --Song 2
    etc....
 -Record 2
  --Song 1
  --Song 2
    etc....
Box 2
 -Record 1
  --Song 1
  --Song 1
etc. etc. etc.

“My way” is very time consuming:

  1. I search the “Box” table using standard SQL.
  2. For each row I call a function that finds each record for that box
  3. For each record I call a function that finds each song for that record

It takes a loooong time to complete since the number of select calls is enormous (many boxes, many recors)

I guess there is a more easy way (from the servers pointy of view) to do the same. Pull dato to php arrays and to the logic there or something else that is clever.

Question:
What is the best practice to get data from a relational database using php?

Br. Anders

  • 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-26T12:54:48+00:00Added an answer on May 26, 2026 at 12:54 pm

    You need to learn about JOINs. Here, you would use two outer joins. That way, you achieve the same result using only one select query, and the amount of work that has to be done by PHP and by MySQL is much less.

    Your SQL would look something like this: (Note that I use SELECT * as a stand-in for the real list of columns, because I don’t know what columns you have – using SELECT * is generally not a good idea)

    SELECT
        *
    FROM
        Box
        LEFT JOIN Record ON Box.BoxID = Record.BoxID
        LEFT JOIN Song ON Record.RecordID = Song.RecordID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need an SQL guru to help me speed up my query. I have
I need to move some code from C# into a Stored Procedure for speed
I need to speed up a query. Is an index table what I'm looking
I need a simple way to test SQL queries for speed. I am not
I need to speed up the import of a sql.gz file into mysql. I
I am new to using prepared statements in mysql with php. I need some
I want to optimize some of the SQL and just need an opinion on
I need to speed up my coding, too much work, so I need be
I need to change the connection speed of a port on a switch via
I need to get up to speed on various ways to integrate ASP.Net C#

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.