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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:08:23+00:00 2026-05-27T10:08:23+00:00

I have not worked with arrays much in PHP. I have a table of

  • 0

I have not worked with arrays much in PHP. I have a table of colors. I want to load it into a multidimensional associative array because I am going to be using that table a lot and don’t want to do selects over and over again.

I did:

$result = mysql_query("select * FROM color") or die(mysql_error());
$colors = "";
 while($colorrec = mysql_fetch_array($result)){
 $colors[$colorrec['ID']][0] = $colorrec['Description'];
 $colors[$colorrec['ID']][1] = $colorrec['HexCode'];
}

then when I want to access a colors information, I can just do something like:

echo "color code WHT";
echo "description ".$colors['WHT'][0];
echo "Hex Code ".$colors['WHT'][1];

Is this the correct way/methodology to do this?

  • 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-27T10:08:24+00:00Added an answer on May 27, 2026 at 10:08 am
    $colors = ""; //what?? this should be array()
    

    This should be something like:

    $result = mysql_query("select * FROM color") or die(mysql_error());
    $colors = array();
    while($colorrec = mysql_fetch_array($result)){
       $colors[$colorrec['ID']] = array();
       $colors[$colorrec['ID']]['Desc'] = $colorrec['Description'];
       $colors[$colorrec['ID']]['Hex'] = $colorrec['HexCode'];
    }
    

    Then you can do:

    echo "color code WHT";
    echo "description ".$colors['WHT']['Desc'];
    echo "Hex Code ".$colors['WHT']['Hex'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have not worked with parameters in ADO.Net very much. I'm writing a custom
I have a double[][] array, and I want to get one row into a
I'm ashamed to say it, but I have to. I have not worked with
So I've never worked with stored procedures and have not a whole lot of
I have worked on iPhone application but not aware of the formalities to submit
I believe several of us have already worked on a project where not only
I have not used generics much and so cannot figure out if it is
I have not seen much support for Grails to develop facebook apps.I was just
have not tested on windows. but in ubuntu when u disconnect from the network,
I have a website that lets people view rows in a table (each row

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.