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

[eluser]hawkeye000[/eluser]
Hello every body
i have this array return from a model function
Code:
/////model function
function getSubCats($catid){

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

                $children = $this->getSubCats($row1->Level_ID);    
                if($children!=null){
    
     $categories[$row1->Level_Title]=$children;
        
            
                }
            }
  
            return $categories;
          
        }

output :
    
Array
(
    [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
Code:
<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>
</optgroup>
<option value="3">GR5</option>
<option value="4">GR6</option>
</select>
#2

[eluser]hawkeye000[/eluser]
???
#3

[eluser]CroNiX[/eluser]
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.
#4

[eluser]hawkeye000[/eluser]
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
Code:
<option value="A">Array</option>
#5

[eluser]Aken[/eluser]
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.
#6

[eluser]hawkeye000[/eluser]
If it just accept one level of multidimensional array .. how can i make a multi-level dropdown menu by it ??
#7

[eluser]Aken[/eluser]
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.
#8

[eluser]hawkeye000[/eluser]
So i have to make it by another way .. thank you dear
#9

[eluser]InsiteFX[/eluser]
I think he wants to create a dropdown menu system. Which he can do a google search on to find one.
#10

[eluser]hawkeye000[/eluser]
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