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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:10:09+00:00 2026-06-07T15:10:09+00:00

Sorry for the beginners question. I’ve searched for an hour now, and can only

  • 0

Sorry for the beginners question.
I’ve searched for an hour now, and can only find info on adding 1 key => value inside the while loop.
I’m aiming for this result. Thanks

$menu = array(  
    '1' => array('id' => 1, 'parentid' => 0, 'title' => 'Apple'),  
    '2' => array('id' => 2, 'parentid' => 0, 'title' => 'Banana'),  
    '3' => array('id' => 3, 'parentid' => 0, 'title' => 'Tangerine'),  
    '4' => array('id' => 4, 'parentid' => 3, 'title' => 'Pear')
);

I’ve tried a number of things but this seems to be the closest.

$menu = array();
while($row = mysql_fetch_array($query)) {
    $menu[] = $row['id'] ;
    $menu[] = $row['parentid'] ;
    $menu[] = $row['title'];
}
  • 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-07T15:10:10+00:00Added an answer on June 7, 2026 at 3:10 pm

    Ahh, looks like you want something like

    $menu = array();
    while ($row = mysql_fetch_array($query)) {
        $menu[] = array(
            "id" => $row['id'], 
            "parentid" => $row['parentid'], 
            "title" => $row['title']
        );
    }
    

    Associative array keys are created using "key" => "value".


    Edit

    Off topic a bit, but I’d strongly recommend learning PDO for your queries. It’s really easy to learn and has a ton of strong points – security and flexibility being the most important – and really takes your scripts to the next level.

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

Sidebar

Related Questions

Sorry for question but I can't find answer anywhere on internet. I couldn't find
Sorry for this simple question, but I can't solve it... There is an example:
sorry for the dummy question but I cannot find a simple and clean way
Sorry for the beginner question, but I can't figure out cProfile (I'm really new
Sorry for asking such a beginner question but I can't figure this out. I
Sorry that this is very much a beginner's question, but yes, I'm only just
sorry for may be stupid question, I am a beginner. what can I do
sorry for the beginner's question, but I find it hard to understand: I have
sorry i'm a beginner and i can't determine how good a question this is,
Sorry for the beginner python question, but I cant find anywhere how to do

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.