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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:53:29+00:00 2026-06-01T12:53:29+00:00

How can I get the record values in the database to be sorted like

  • 0

How can I get the record values in the database to be sorted like this in an array. Supose I am adding the day no.

array
 [0] => array=>'id'=>'26' 'date'=>'26'

 [1] => array=>'id'=>'27' 'date'=>'27',
        array=>'id'=>'28' 'date'=>'27',
        array=>'id'=>'29' 'date'=>'27'

 [2] => array=>'id'=>'30' 'date'=>'29'

 [3] => array=>'id'=>'31' 'date'=>'31',
        array=>'id'=>'32' 'date'=>'31',
        array=>'id'=>'33' 'date'=>'31'

Basically, I want to add an array to the same index if the next id contains a record with the same date (day no) of the month. Otherwise add it normally.

Right now, My function is adding the rows of the record without sorting it in the format I want it to be in.

The reason I want it to be in this format is because, I need to run the foreach, and if 1 day contains 2 records, then it will append another <li> into my unordered list.

public function getArticles()
{
        $sql = 'CALL getArticles()';        
        $articles = Array();

        if (Model::getConnection()->multi_query($sql)) {
            do {
                if ($result = Model::getConnection()->store_result()) {
                    while ($row = $result->fetch_assoc()) {     
                        array_push($articles,$row);                         
                    }
                $result->free();
                } 
            } while (Model::getConnection()->next_result());
        }
        return $articles;
}
  • 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-01T12:53:31+00:00Added an answer on June 1, 2026 at 12:53 pm

    I don’t recognize what some of your code is doing, but I think this is the important part.

    while ($row = $result->fetch_assoc()) {     
        if (!isset($articles[$row['date']])) {
            $articles[$row['date']] = array();
        }
        $articles[$row['date']][] = $row;                        
    }
    

    The only difference will be that your array will be keyed on the date instead of incrementing from zero. If you really want it reindexed, you can do…

    array_values($articles);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know how we can get record count using reference cursor in
How can I get a record id after saving it into database. Which I
I want to get records from the database using EF and assign the values
So i need to figure out how i can get a record count value
Using the unix dig command, I can get the following MX record: $ dig
How can I get specific number of records from nhibernate like 10 or 15
I am trying to make this form with checkboxes get values 1 or 0,
I have an sqlite database on android created like this: sqlite> .schema CREATE TABLE
I save some values from database using this function (i've been replaced Vector, because
I'm trying to build an edit page for a database record that can be

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.