SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Feb 2004
    Location
    toronto
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb help with checkboxes (multidimensional array) in HTML forms

    Hi All,

    Happy Monday!

    I want to show the fields of each table in my DB as checkboxes in a user form that user can check and my program selects the column data from the DB depeneding on checked boxes.

    e.g.

    Table 1

    fields as checkboxes

    Table 2

    fields as checkboxes

    How do I get the info about the checked fields in each of the tables?


    I hope it's clear enough.

    Thank you all.

    lkj

  2. #2
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    make the checkboxes in your form ...

    <input type="checkbox" value="1" name="checkbox[1]" />
    <input type="checkbox" value="1" name="checkbox[2]" />
    etc

    then loop through the $_POST['checkbox'] array

  3. #3
    SitePoint Member
    Join Date
    Feb 2004
    Location
    toronto
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by firepages
    make the checkboxes in your form ...

    <input type="checkbox" value="1" name="checkbox[1]" />
    <input type="checkbox" value="1" name="checkbox[2]" />
    etc

    then loop through the $_POST['checkbox'] array
    would that work for multidimensional array? pl. detail the code onve user has submit the form? Thx. lkj

    My code:

    //on Post I get Error - isn't Array
    if (isset($_POST['submit'])):

    $an = $_POST['tableone'];
    if (!is_array ($an)) {
    print "Is not ARRAY\n";
    }
    print "an === $an\n";
    foreach ($an as $catID) {
    print ("names2 = $catID <br />\n");
    }
    ?>

    <?php
    else: // Allow the user to enter a new joke

    print ("<p>Tables in cookbook database/p>\n");
    ?>


    <form action="<?=$_SERVER['PHP_SELF']?>" method="post">

    <?php
    # Connect to database, display table list, disconnect
    # Connect to database, display table list, disconnect
    $conn_id = @mysql_connect() or die("Could not connect : " . mysql_error());

    $result_id = mysql_query ("SHOW TABLES", $conn_id);
    #$table_names = array();
    while (list ($tbl_name) = mysql_fetch_row ($result_id)) {
    print ("<br /> $tbl_name<br />\n");
    $names[$tbl_name] = get_column_info ($conn_id, $tbl_name, "name");
    $labels = $values = $names[$tbl_name];
    $quote = '"';
    $name = $quote . $tbl_name .'[]' . $quote;
    $default = array();
    print (make_checkbox_group ($name, $values, $labels, $default, FALSE));

    }
    ?>
    <p><input type="submit" name="submit" value="SUBMIT" /></p>
    </form>

    <?php
    mysql_free_result ($result_id);
    mysql_close ($conn_id);

    endif;

    print ("</body>\n");
    print ("</html>\n");
    ?>

  4. #4
    SitePoint Zealot oivaf's Avatar
    Join Date
    Apr 2003
    Location
    Mexico
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mmm have you tried
    PHP Code:
    <input type="checkbox" value="1" name="checkbox[tableone][]" />
    <
    input type="checkbox" value="2" name="checkbox[tableone][]" /> 
    ?

    HTH


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
  •