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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:03:03+00:00 2026-05-15T08:03:03+00:00

Okay, here’s what I’m trying to do. I am running a MySQL query for

  • 0

Okay, here’s what I’m trying to do. I am running a MySQL query for the most recent posts. For each of the returned rows, I need to push the ID of the row to an array, then within that ID in the array, I need to add more data from the rows. A multi-dimensional array.

Here’s my code thus far.

$query = "SELECT * FROM posts ORDER BY id DESC LIMIT 10"; 
$result = mysql_query($query);

while($row = mysql_fetch_array($result)){

            $id = $row["id"];
            $post_title = $row["title"];
            $post_text = $row["text"];
            $post_tags = $row["tags"];
            $post_category = $row["category"];
            $post_date = $row["date"];



}

As you can see I haven’t done anything with arrays yet. Here’s an ideal structure I’m looking for, just incase you’re confused.

The master array I guess you could call it. We’ll just call this array $posts.
Within this array, I have one array for each row returned in my MySQL query.
Within those arrays there is the $post_title, $post_text, etc.

How do I do this? I’m so confused.. an example would be really appreciated.

-Dylan

  • 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-15T08:03:03+00:00Added an answer on May 15, 2026 at 8:03 am
        $master[$id]['post_title'] = $post_title;
        $master[$id]['post_text'] = $post_text;
        // etc
    

    or, less code. With this one, you can get rid of where you set all those variables:

        $master[$row["id"]]['post_title'] = $row["title"];
        $master[$row["id"]]['post_text'] = $row["text"];
        // etc
    

    Edit in answer to comment:

    foreach( $master as $row )
    {
        echo $row['post_title'];
    }
    
    // or if you know the id
    
    echo $row[$id]['post_title'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, here's what I'm doing with a MYSQL SELECT query. SELECT * FROM Customers
Okay here is what I'm trying to do: I have a model object that
Okay so here is the deal. As the question states, I'm trying to POST
Okay, here's what I'm trying to do: I'm trying to use PHP to develop
Okay here is what I'm, trying to do I want to escape the period
Okay so here's the thing: I have a linq query which loads approx. 1000
Okay, so here is what I'm trying to do. The user inputs a number.
okay so here is my problem in my main project I'm trying to fire
Okay here's my situation. I have the following branches development development-kirby (270 commits ahead
Okay so here's what I'm doing. I'm making a request to a server to

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.