#1
  1. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    St. Louis
    Posts
    20
    Rep Power
    0

    multiple checkbox selections populating multiple fields


    Hi everyone,

    I am using the following snippet of code to dynamically create a series of checkboxes...
    PHP Code:
    $result mysql_query("SELECT teams.teams from teams");
    $myrow mysql_fetch_array($result);

      if(
    $myrow)
      {
        echo 
    "<center><table border=\"1\" bordercolor=\"#ff0000\" cellpadding=\"3\" cellspacing=\"0\">\n";

        do
        {
          
    $teams $myrow["teams"];
          
    $checkbox '<input type="checkbox" name="winners[]" value="'$teams .'">'$teams .'';
           
          
    printf("<tr><td>%s</td></tr>\n"$checkbox);      
        }
        while(
    $myrow mysql_fetch_array($result));

        echo 
    "</table></center>\n";
      } 
    Easy enough... my problem is figuring out how to force each checkbox selection to become a new field in a chosen table.

    I am using this....
    PHP Code:
        $winners implode($winners",");
        
    $add_winners addslashes($winners); 
        
    $result mysql_query
                  
    ("INSERT INTO winners VALUES (NULL,'$add_winners')"); 
    This will work fine if the user picks one checkbox, but if multiple ones are chosen, then all the variables are stuffed into one single database record.

    Any ideas how to get each 'checked' checkbox to populate successive fields rather than a single on per click?

    Thanks for any help
    Rob
  2. #2
  3. // no comment
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2001
    Posts
    1,643
    Rep Power
    43
    dont do an implode() if you want to separate the values of the checkbox.
    PHP Code:
    <?
      
    if (is_array($winners)) {
        for (
    $i 0$i count($winners); $i++) {
          
    $add addslashes($winners[$i]); 
          
    $result mysql_query ("INSERT INTO winners VALUES (NULL,'$add')");
        }
      }
    ?>
  4. #3
  5. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    St. Louis
    Posts
    20
    Rep Power
    0
    right on roninblade....thank you

IMN logo majestic logo threadwatch logo seochat tools logo