Welcome Guest, Not a member yet? Register   Sign In
Multidimensional array in form_dropdown give me an array

Hello every body
i have this array return from a model function
/////model function
function getSubCats($catid){

        $query= "select * from levels where Parent_Level='$catid'";
        $rst =  $this->db->query($query);
            return null;
            foreach($rstt as $row1) {
                $categories[$row1->Level_ID] =$row1->Level_Title;

                $children = $this->getSubCats($row1->Level_ID);    
            return $categories;

output :
    [2] = GR4
    [GR4] = Array
            [5] = A
            [A] = Array
                    [7] = e

            [6] = B

    [3] = GR5
    [4] = GR6
How can i convert it to dropdown menu? i tried to use form_dropdown put it gave me this
<select name="Grades">
<option value="2">GR4</option>
<optgroup label="GR4">
<option value="5">A</option>
<option value="A">Array</option>
<option value="6">B</option>
<option value="3">GR5</option>
<option value="4">GR6</option>


What's the question? It's already in the form of a dropdown according to your output. What are you expecting it or wanting it to do?

An array of Key => Values will produce a normal dropdown with the Key being the value sent and the Value being the text shown in the dropdown option. A multidimensional array will create a dropdown with option groups. If the Key is another array, that key will be the option group label and it's array will produce the options for that group, just like you have above.

But i cannot do it by form_dropdown "form_helper"
This is the question .. can i do this array with form_dropdown ?
coz i tried but i got this
<option value="A">Array</option>

form_dropdown() only expects a maximum of one level of multidimensional array. That's why the others work but "A" doesn't. You'll need to manipulate your data into an array that form_dropdown() expects.

If it just accept one level of multidimensional array .. how can i make a multi-level dropdown menu by it ??

I have no idea what a "multi-level dropdown" is supposed to mean. form_dropdown() only allows one sublevel of array options, and uses that to create optgroups. You can't use an array inside an array, or you'll get the result you're getting. You need to format your array differently.

So i have to make it by another way .. thank you dear

I think he wants to create a dropdown menu system. Which he can do a google search on to find one.

Yes but i am newbie CI user and i didn't know how can i make it by model and controller .. now after searching .. i will make a class to manage it and write a function to create this dropdown menu

Sorry for my English language Smile

Theme © iAndrew 2016 - Forum software by © MyBB