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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:14:54+00:00 2026-06-08T19:14:54+00:00

Say I have a query the following query run: Edit Added order clause because

  • 0

Say I have a query the following query run:

Edit

Added order clause because the real sql statement has one.

SELECT description, amount, id FROM table ORDER BY id

In this instance, the ID is not unique to the dataset. It would return something like this.

    Description    Amount    ID
    -----------    ------    --
1    Hats            45       1
2    Pants           16       1
3    Shoes           3        1
4    Dogs            5        2
5    Cats            6        2
6    Waffles         99       3

What I need to do is enclose each section of IDs in it’s own div (So rows 1,2,3 in one div, 4,5 in another div and 6 in it’s own div).

There are tons of solutions to this but I just can’t think of one that isn’t overly complicated.

I want to be able to keep the SQL how it is and somehow sort the data set in PHP so that I can loop through each section of the dataset while looping through the dataset as a whole.

Some kind of array would work but the structure of it is stumping me.

How can I get this to work? PHP solutions would be idea but theoretical will help too.

  • 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-08T19:14:56+00:00Added an answer on June 8, 2026 at 7:14 pm

    A simple serial solution might look something like this:

    $curId = '';       // track working id
    $firstDiv = true;  // track if inside first div
    
    // open first div
    echo '<div>';
    
    // foreach $row
    {
        // when id changes, transition to new div, except when in first div
        if ($row->$id != $curId) {
            if ($firstDiv) {
                $firstDiv = false;
            } else {
                // start new div
                echo '</div>';
                echo '<div>';
            }
            $curId = $row->$id;  // track new current id
        }
    
        // display contents of current row
    }
    
    // close last div
    echo '</div>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have the following SQL query SELECT id, name, title, description, time
Say I have the following query OData Linq Query (run against http://odata.netflix.com/v2/Catalog ): Genres.Where(x=>x.Name==Adventures)
Say I have the following query ICriteria query = session.CreateCriteria(typeof(T)); How can I find
Say I have a query like this: one two three, if I replace with
I have the following mysql table called test. lets say it has the data
Say I have an html file that I have loaded, I run this query:
Lets say I have query that gets following List Item Objects with Set of
Say I have the following query on the Netflix OData Endpoint: Titles.Where(x=>x.AverageRating > 3.0)
I have a SQL query that is returning a table like the following: id
If I have the following query, is it possible to be able to run

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.