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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:14:33+00:00 2026-05-20T02:14:33+00:00

I want an array to be declared like $value=array(‘apple’=>’red’, ‘mango’=>’yellow’). now i want this

  • 0

I want an array to be declared like $value=array('apple'=>'red', 'mango'=>'yellow').
now i want this values to be fetched from the database.
both the apple and the red.
suppose this coloures are saved in table called ‘colors’ and fruits in the table ‘fruits’, with the color_id.
now how to fetch them and put inside this array.

i tried to put the codes in side the bracket like array(code to fetch) but it did’nt work.
anybody can help?

table->fruit(fruit_id, color_id, fruit_name)
table-> color(color_id, color_name)

 $result=mysql_query("select * from
 fruit_table");
 while($row=mysql_fetch_array($result)){
     $row_color-mysql_fetch_array(mysql_query("select color_name from colors where
 color_id=$row['color_id']"));
 $val[]="$row['fruit_name']=>$row_color[color_name]";

 } 
$data=implode(",",$val);
 $value=array($data);

thanxx in advance.

  • 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-20T02:14:34+00:00Added an answer on May 20, 2026 at 2:14 am

    There are two things you will have to do.

    1. Perform a query to get the required information from the database.
    2. Turn the result from the query into the format you want.

    Here’s some example code (assuming you have already made a successful connection to the database).

    Assumptions I’ve made on your database schema are:

    • You use id as the primary key in both tables
    • name is the field that contains the color/fruit names

    If they are correct it should work, otherwise minor adjustments are required to the query

    $result = mysql_query('
        SELECT fruits.name as fruit, colors.name as color 
        FROM fruits 
        JOIN colors 
        ON fruits.color_id = color.id');
    
    if (!$result) {
        die(mysql_error());
    }
    
    $value = array();
    
    while ($row = mysql_fetch_assoc($result)) {
        $value[$row['fruit']] = $row['color'];
    }
    
    mysql_free_result($result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I Declared my Array like this: Dim invoice_discountitems(100, 1) As String Now i set
I want to my array, somthing like this: array(userid=>username,1=>ganeshfriends,2=>tester) mysql query something like this:
If I want to return an immutable array like this + (NSArray *)ids but
I have a procedure declared like so: procedure MyProc(List: Array of string); I want
i have a multidimensional array whose index/keys (not the values) are like this: this
I have an array declared in my header file like this: int snapshot[kSnapshotSize]; which
I saw a function declared like this: public static function factory($file=null, array $data=null, $auto_encode=null)
I have one array. I want that array to retain its value between function
I want to sort array A based on values in Array B actually in
From below array i want the value of _sql to be displayed or we

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.