user1337603
user1337603

Reputation: 285

PHP array overwrites itself

Everytime I pass post array data it overwrites itself every time a new selection is passed. I want it to add to the previous selection and keep growing.

Im banging my head trying to work this out, is it due to the array thats passed not having enough dimensions or the right key??

echo '<input type="checkbox" id ="menu" name="'.$did.'['.$result2['cid'].']'.'['.$result2['id'].']" value="'.$result2['id'].'">'.ucwords($result2['name']).'<br />';
if($array){    
    foreach ($array as $key => $value){        
        if(is_array($value)){
            foreach ($value as $key => $value){
                $query = mysql_query("SELECT title FROM menuCategory WHERE cid = $key");
                $result = mysql_result($query,0);                      
                echo '<h1>'.ucwords($result).'</h1>';             
                foreach ($value as $key => $value){
                    echo '<input type="hidden" name="'.$key.'" value ="'.$value.'">';  
                    $query = mysql_query("SELECT cid, id, name FROM menuBread WHERE id = $value");
                    $result = mysql_fetch_assoc($query);
                    echo ucwords($name = $result['name']).'<br />';
                }                   
            } 
        } 
    }
}

Upvotes: 0

Views: 589

Answers (1)

Naftali
Naftali

Reputation: 146310

You are using the same variable names for both the inner and outer foreach loops which is overwriting the variables....

Change the names in one of the places, and you should be good.

Upvotes: 6

Related Questions