SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    619
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Add values of multiple selected checkboxes with comma separator

    hi all

    there are around 30 checkboxes.

    i want to insert all selected checkboxes values with a comma separator in
    database in one single column.

    i m able to echo all the checkboxes selected through the below code

    Code:
    <input  type="checkbox" value="Battery"  name="checkbox[]" id="checkbox[]" />
    PHP Code:
    for ($i=0$i<count($_REQUEST['checkbox']);$i++) {
    echo 
    "chosen<br />$i. ".$_REQUEST['checkbox'][$i];

    output is
    Code:
    0. battery
    1. rocket
    2. pineapple
    i want to insert all selected checkboxes values with a comma separator in
    database in one single column.

    so what should i write in my query

    Code:
    $query = "insert into checkbox table (checkboxes) values()"
    vineet

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    To get the values into a list:
    PHP Code:
    $List implode(', '$_REQUEST['checkbox']); 
    However, I would recommend a different row for each value, with a column value in common to group them together, e.g. a GroupID.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    619
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    thanks jake

    that worked fine as needed.

    if i need to replace comma with number like 1,2,3 then what do i have to do

    vineet


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
  •