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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:48:35+00:00 2026-06-12T06:48:35+00:00

When I retrieve articles information from a mysql database I got an array like

  • 0

When I retrieve articles information from a mysql database I got an array like this:

Array
(
    [0] => Array
        (
            [CategoryID] => 3
            [CategoryName] => Test Category
            [Parent] => 0
            [Thumb] => 0
            [sort] => 8
            [ArticleID] => 2
            [ArticleCatgories] => 9,4,3
            [ArticleTitle] => vxcvxcvx
            [ArticleBody] => xcvxcvxcvxcv
            [InGroup] => 0
            [GroupID] => 0
            [Published] => 1
            [PublishTime] => 
            [TermID] => 11
            [TermSlug] => xcvxcvxcv
            [RelatedID] => 2
            [TermType] => article
        )

    [1] => Array
        (
            [CategoryID] => 4
            [CategoryName] => Test Image
            [Parent] => 0
            [Thumb] => 0
            [sort] => 4
            [ArticleID] => 2
            [ArticleCatgories] => 9,4,3
            [ArticleTitle] => vxcvxcvx
            [ArticleBody] => xcvxcvxcvxcv
            [InGroup] => 0
            [GroupID] => 0
            [Published] => 1
            [PublishTime] => 
            [TermID] => 11
            [TermSlug] => xcvxcvxcv
            [RelatedID] => 2
            [TermType] => article
        )

    [2] => Array
        (
            [CategoryID] => 9
            [CategoryName] => Test Images
            [Parent] => 0
            [Thumb] => 7
            [sort] => 2
            [ArticleID] => 2
            [ArticleCatgories] => 9,4,3
            [ArticleTitle] => vxcvxcvx
            [ArticleBody] => xcvxcvxcvxcv
            [InGroup] => 0
            [GroupID] => 0
            [Published] => 1
            [PublishTime] => 
            [TermID] => 11
            [TermSlug] => xcvxcvxcv
            [RelatedID] => 2
            [TermType] => article
        )
} 

And because the article is in more than one category, it retrieve the article information more than once.
What I need to do is to combine the category names into a sub array if they have the same ArticleID so the result become like:

Array
(
    [0] => Array
        (
            [CategoryName] => array('Test Category','Test Image','Test Images');
            [Parent] => 0
            [Thumb] => 0
            [sort] => 8
            [ArticleID] => 2
            [ArticleCatgories] => 9,4,3
            [ArticleTitle] => vxcvxcvx
            [ArticleBody] => xcvxcvxcvxcv
            [InGroup] => 0
            [GroupID] => 0
            [Published] => 1
            [PublishTime] => 
            [TermID] => 11
            [TermSlug] => xcvxcvxcv
            [RelatedID] => 2
            [TermType] => article
        )
}
  • 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-12T06:48:36+00:00Added an answer on June 12, 2026 at 6:48 am

    You can build a new array using ArticleID as the keys:

    $final = array();
    foreach ($rows as $row) {
        $id = $row['ArticleID'];
        if (isset($final[$id])) {
            // we've already seen this article
            // append to categoryname array
            $final[$id]['CategoryName'][] = $row['CategoryName'];
        } else {
            // this is the first article occurrence
            // turn categoryname into array first
            $row['CategoryName'] = array($row['CategoryName']);
            $final[$id] = $row;
        }
    }
    
    print_r($final);
    

    Output based on your question:

    Array
    (
        [2] => Array
            (
                [CategoryID] => 3
                [CategoryName] => Array
                    (
                        [0] => Test Category
                        [1] => Test Image
                        [2] => Test Images
                    )
    
                [Parent] => 0
                [Thumb] => 0
                [sort] => 8
                [ArticleID] => 2
                [ArticleCatgories] => 9,4,3
                [ArticleTitle] => vxcvxcvx
                [ArticleBody] => xcvxcvxcvxcv
                [InGroup] => 0
                [GroupID] => 0
                [Published] => 1
                [PublishTime] =>
                [TermID] => 11
                [TermSlug] => xcvxcvxcv
                [RelatedID] => 2
                [TermType] => article
            )
    
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To retrieve k random numbers from an array of undetermined size we use a
I retrieve data from db like that: select * from MOVIE_COMMENT where USER_ID =
I retrieve embed code videos from my database. However, in db they are 650
i have a search query which will retrieve information from 3 tables i made
I am using the HtmlAgilityPack to retrieve information from a web page and, at
I'm trying to retrieve articles through wikipedia API using this code $url = 'http://en.wikipedia.org/w/api.php?action=parse&page=example&format=json&prop=text';
Is it possible to crawl user information programmingly from social network like Facebook? I
I'm using curl to retrieve information from wikipedia. So far I've been successful in
I want to retrieve some tags from my database, they are in the form:
Retrieve code from json. C#code:- var collection = getsortcat.Select(x => new { idterm =

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.