Skip to content
Advertisement

populating php dropdown options with mysql result values shows “Array” when I sort() the array

Edit: When I commented out the sort() line, now it is populating properly. PHP sort looks in-place so I don’t know what happened.

I also had to insert a redundant <div> right above the form to either get the array of option values from a session variable or calling the querying function to get it populated.

JavaScript

Coming from Python, this feels very weird and somewhat clunky.

First I thought it was my problem using associative arrays so I used a linear array to store my query results. My query:

JavaScript

I saw somewhere on S.O. that 1=1 will not hurt performance so left it in.

When I call the querying function in my view page and step through on debugger, I can clearly see the array holds the correct query results:

food_array in debugger

And I also checked each value of $food in the array to make sure it was there.

Then I try to populate the dropdown following this: https://stackoverflow.com/a/5189689/13865853 or this: https://stackoverflow.com/a/43334388/13865853

But all I get are values of “Array” as dropdown options.

Array only

My code:

JavaScript

Advertisement

Answer

What ended up working was:

JavaScript

so using {} to enclose the variable. However, I was unable to trim() nor str_replace() the /‘s.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement