SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,106
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post parameters array problem

    Hi, can i ask is it possible to insert this in my table

    suppose i have this function addgroup($groupname,$groupsize,$grouplevel)

    now those parameters in addgroup function are posted in array

    how do insert them to my table ?

    I tried to use foreach but i did not achieve it gives me syntax error.
    Code:
     function  addgroup($groupname,$groupsize,$grouplevel){
         foreach($groupname as $gp,$groupsize as $gpsize, $grouplevel as $gplevel){
     
                  Insert statement here ................    
       }  
       
    }
    I use foreach so that i can extract the values and insert them in my table during loop...This is okay if it's only one parameter but how do I solved that kind of problem with multiple parameter and with and array of values?



    Thank you in advance.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Who knows.
    What do the arrays contain? How is the table structure? What is the code you have where the ..... are?

  3. #3
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    725
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    I would suggest building your arrays with common keys, then use this key to get matching values.
    PHP Code:
    <?php
    //As a sample, build each array with a common loop.  Either assign a common KEY or leave blank.
    $groupname[] = "BIG GROUP";
    $groupsize[] = "BIG";
    $grouplevel[] = "FIRST CLASS";
    //These "arrays" will all have a common    KEY of 0

    // Use thses common keys to identify matching values
    function  addgroup($groupname,$groupsize,$grouplevel){
        foreach(
    $groupname as $groupKEY => $gp){
            
    $gpsize $groupsize[$groupKEY];
            
    $gplevel $grouplevel[$groupKEY];
            
    //Insert statement here ................    
        
    }
    }
    ?>

  4. #4
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,106
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi, Drummin
    Thank you it's working


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •