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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:08:38+00:00 2026-05-13T22:08:38+00:00

I have been asked to post a new question about how to correctly sort

  • 0

I have been asked to post a new question about how to correctly sort my data. Here is what I am trying to do. I want to make a single trip to my database for all of the data that I will need for this page. Once I have the data returned from the database, I need to sort it out and use it.

For brevity, I am only posting a single row of data. There are, in actuality, 8 rows being returned. Here is the structure of the data that is being returned:

col1    col2    col3    col4    col5    col6    col7    col8    col9

Now, here is the problem I am having. Columns 1 through 7 hold a 1:1 dataset. Columns 8 and 9 however, hold numerous rows, hence the 8 total rows. Because I have columns 1 through 7 mixed in with the 1:M rows, I am echoing rows 1-7 7 times more than I need to.

How can I resolve this?


Let me just add that there are 4 inner joins being used in this query. One of the tables, holds page specific data that I only need to access once. The other joins are what are creating the other rows. Let me just say tat the output of this resultset is absolutely correct. I just need to figure out how to sort it.


OK, this should make sense….

dealerId  empId  lotId  rackId  porterId  vehicle  vin
1         1      1      1       1         Geo      12JI997676JH
1         1      1      1       1         Ford     87HJ879854HS
1         1      1      1       1         BMW      567876HCS456
1         1      1      1       1         Mercedez 1JI8787GS687

In this set, notice that I have 4 rows of repeating data. What I need is this:

dealerId  empId  lotId  rackId  porterId
1         1      1      1       1

AND then for the multiple rows, I need this:

vehicle  vin
Geo      12JI997676JH
Ford     87HJ879854HS
BMW      567876HCS456
Mercedez 1JI8787GS687

So, this setup now gives me the single row of my dealer data and I now have a new array with the vehicle 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-13T22:08:38+00:00Added an answer on May 13, 2026 at 10:08 pm

    OK, so the question is, how do you want to use this data? If you want to display it in this fashion, one row per vehicle, it makes sense to fetch the data JOINed and just go through it:

    foreach ($row as $vehicle) {
        echo "$vehicle[vehicle] … $vehicle[dealerId]\n";
    }
    

    Each retrieved row would represent one set of related data.

    If, OTOH, the JOINed vehicle data doesn’t actually have to do much with the dealerIds etc, it makes a lot more sense to retrieve these two things in separate queries. It’s probably faster too.

    Retrieve (and store, to begin with) data in the simplest way that makes sense so you have to do as little post-massaging in your PHP code as possible. Don’t set the goal to be “retrieve everything in a single query” just because. If you fear several trips to the database are too expensive, they’re probably not. Your time is much more valuable than the split second it takes to make a second request.

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

Sidebar

Related Questions

I asked a question yesterday about password safety... I am new at security... I
We have been asked to provide a data reporting solution. The followng are the
I realize this question (or questions that look like this) have been asked over
I am more than convinced that similar questions have been asked here but I
I have been asked this a lot lately so I thought I'd post the
This question has been asked a number of times, I have noted, but none
i have been asked by a client to allow users to upload and post
It looks like this question has been asked before, here and in other places
I am brand new to Sitecore and have been asked to extend the company's
This question have been asked already, but the answers seems still incomplete. The profound

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.