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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:18:32+00:00 2026-06-16T04:18:32+00:00

Mysql or through PHP? I have a design that calls for grouping articles by

  • 0

Mysql or through PHP?

I have a design that calls for grouping articles by their date. The date will be a heading and all articles from the latest 10 will be grouped under each heading. The date can be anything and/or highly sporadic, the articles must be in descending order, etc.

I figure i would have to

  1. retrieve the last 10 articles and put them in a multi-dimensional array like so:

    $allretrieved = array ( array ( id => a, date => b, title => c, body => d, image => e, etc.),
                            array ( id => a, date => b, title => c, body => d, image => e, etc.),
                            etc.
                    );
    
  2. then group the array by using a method I don’t fully understand ( extract into another array? Would someone explain this function to me?)

    $date_groups[] = array();
    $group = '';
    
    foreach( $date_groups as $key=>$val ) {
        if($key == 'date'){
             $group = $val;
        }
    $comment_groups[$group][] = $val;
    }
    
  3. and then sort the groups?

Or should I sort beforehand?

is doing it at the MySql level faster? more efficient?

EDIT: Best Method I have found for this:
Basic PHP MySQL array grouping question

  • 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-16T04:18:35+00:00Added an answer on June 16, 2026 at 4:18 am

    At some point where your dataset isn’t too big, sorting with mysql should be faster if indexes are correctly added since default mysql indexes are b-tree. In your case, bringing the data and looping over it you will have a O(n) thus the sorting will take more as the data gets bigger.

    I recommend you to take a look to your database schema, use explain to see how indexes are being used in the query you are running and benchmark. AGAIN: this will depend of your data.

    now, for a sake of dreaming: Once your data is big enough to make the sorting too slow in mysql then you should switch something where you can sort in parallel using map-reduce or something like that, but given the nature of your post I think you are safe for now.

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

Sidebar

Related Questions

I have $_POST in form through PHP into a MYSQL DB that have apostrophes
I have create a simple grid that retrieves data from a server through php.
I have a table being pulled from MySql through PHP.. The TD in the
I have design my database on MySQL and link it through php. how can
i have created a forum using php/mysql and users login through facebook using php
I am sending 2 arraylist from android to php through url . Mysql contains
I have this markup dinamically generated through PHP/MySQL <div id=sortable> <h3>Italy</h3> <ul> <li id=row_1>Record
I have to adapt a PHP-script that is connected to a extremely messy database-design.
Possible Duplicate: How to go through mysql result twice? I have a PHP script
I have following Template string in mysql which i fetch through php. $msg =

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.