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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:42:33+00:00 2026-05-24T05:42:33+00:00

I am populating an array from a MySQL Database, the problem is I get

  • 0

I am populating an array from a MySQL Database, the problem is I get 9 blank fields in my dropdown box that I am trying to populate it with. What did I do wrong?

php code:

while($row = mysql_fetch_assoc($results))
{
    $options[] = array(
                        Name => $row['Name'], 
                        Value => $row['Value'], 
                        ID => $row['CID']
                      );
}

dropdown box:

for ($i = 0; $i < 9; $i++)
{
    print '<option id="'.$options[$i]["ID"].'" value="'.$options[$i]["Value"].'">'
          .$options[$i]["Name"].
          '</option>'."\n";
}
  • 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-24T05:42:34+00:00Added an answer on May 24, 2026 at 5:42 am

    Your quotes are backwards in your array

    while($row = mysql_fetch_assoc($results))
    {
        $options[] = array("Name" => $row['Name'], "Value" => $row['Value'], "ID" => $row['CID']);
    }
    

    Also, using an associative array in double quotes requires you to do this:

    echo "I want to print out this: {$arr['index']}";
    

    If you don’t do it this way, it (should) result in a parse error.

    You might notice that this also works

    echo $arr[index]
    

    But this is not good practice because if there is a constant through a define() named index, all of your statements will use your constant’s definition instead of the string you intended.

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

Sidebar

Related Questions

PROBLEM I have a nested PHP array that I need to populate from flat
I have a mysql fetch that is populating an associative array with columns from
I am trying to populate a dropdown list from database. In my view file
I am populating a combobox dropdown with node fields from an Xml document. I
I'm trying to get some data from my database, and then pass it into
I have a simple content edit form (Zend_Form) that I populate() with an array
Following the Android sample for populating a ListView , I query an array from
I am having trouble populating a datagridview with items from a string array. Here
I want to create an array, populating it while reading elements from a .txt
I'm populating my tableview from an array. And this array is created by SQLite

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.