Dropboxes, query, save selections id's comma sep.

Discussion in 'PHP' started by b.devroey, Dec 2, 2011.

  1. #1
    Hello,

    I have a part of my form filled with drop-boxes, those are being loaded dynamically by a query,
    how can i save the ID from every value that is checked by users, comma sepperated...

    <html>
    <table width="100%" border="0" cellpadding="0">
    <?php
    $objCon1 = new cDatabase;
    $objFun1 = new cFunction;
    if(($link=$objCon1->connectMYSQL())!=FALSE){ // connect mysql
    if($objCon1->connectDB($link)!=FALSE){ // select databasen;
    $sQry = "select * from categories";
    if($result=@mysql_query($sQry)) {

    ?>
    <tr><?php while($rec=mysql_fetch_array($result)) { ?>
    <th width="344" align="left" valign="top" scope="col"><p><?php echo $rec['Catname']; ?><br>
    <?php $sQry1 = "select * from subcategories where subcategories.catid=".$rec['Catid']."";
    if($result1=@mysql_query($sQry1)) {
    while($rec1=mysql_fetch_array($result1)) { ?>
    <input type="checkbox" name="checkbox2" id="checkbox2">
    <?php echo $rec1['Subcatname']; ?> <br>

    <?php } } ?>
    </th>
    </th>
    <?php }} } } ?>
    </tr>

    </table>
    </html>
     
    b.devroey, Dec 2, 2011 IP
  2. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #2
    Try these changes within the loop:

    <input type="checkbox" name="checkbox2[]" id="checkbox2" value="<?php echo $rec1['Subcatname']; ?>">
    <?php echo $rec1['Subcatname']; ?>
    HTML:
    (added square brackets to element name [] and added value attribute)

    This will submit the element as an array so you can pick it up by looping $_POST['checkbox2'];
     
    mfscripts, Dec 2, 2011 IP