Results 1 to 7 of 7

Thread: Echo Multiple Values From One Form Element Name?

  1. #1

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065

    Echo Multiple Values From One Form Element Name?

    hey ya,

    OK Say i have this form:
    Code:
    <form action=form.php method=post>
    <input type=checkbox value=1 name=MiD><BR>
    <input type=checkbox value=2 name=MiD><BR>
    <input type=checkbox value=3 name=MiD><BR>
    <input type=checkbox value=4 name=MiD><BR>
    <input type=checkbox value=5 name=MiD><BR>
    <input type=checkbox value=6 name=MiD><BR>
    <input type=checkbox value=7 name=MiD><BR>
    <input type=checkbox value=8 name=MiD><BR>
    <input type=checkbox value=9 name=MiD><BR>
    <input type=submit><BR>
    </form>
    how can i loop thru the values, etc, and do an echo for each value, if the chkbox is checked?

    (Sorta like Yahoo! Mail does with its delete & Move ETC?)

    Like, if some1 checks 1, 2, 3, 5, 6, and 9, - My PHP code, will then loop thru the checked value's, and delete a SQL Record from the MySQL Database, & Echo that the id was Deleted And so on, but for say 5, 7, and 8, nothing gets done, since they aint checked,..

    : Hoping you know what i mean, and even more, how to do what i wanna do
    Wayne

  2. #2
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    technically it should be "MiD[]" (in quotes) and you would loop through it as if it were an array:

    PHP Code:
    <?php
      
    for($i=0;$i<sizeof($_POST['MiD']);$i++)
        echo 
    "MiD[$i] = {$_POST['MiD'][$i]}<br />\n";
    ?>
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  3. #3

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    OK,

    & If i have total gibberish as the value? or?

    Or is this takin into account (Can u explain it a little ? )

    Tnx
    Wayne

  4. #4
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    PHP Code:
    <?php
      
    // Loop through the length of the array 
      
    for($i=0;$i<sizeof($_POST['MiD']);$i++)
        
    // For each element print outs its value
        
    echo "MiD[$i] = {$_POST['MiD'][$i]}<br />\n";
    ?>
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  5. #5

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    ok, so Thinking about this,

    when the actual form is submitted as an array (like this),

    is it automatically given its own array number, when its retrieved by PHP / The server,

    Like if u use MyArray()=Split(Stuff,"?")

    or something like dat then?

    Ta.
    Wayne

  6. #6
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Yes when working with forms if you give them the same name and add [] to the end of the name it will turn it into an array, example:

    Code:
    <form action="form.php" method="post">
    <input type="checkbox" value="1" name="MiD[]"><br />
    <input type="checkbox" value="2" name="MiD[]"><br />
    <input type="checkbox" value="3" name="MiD[]"><br />
    <input type="checkbox" value="4" name="MiD[]"><br />
    <input type="checkbox" value="5" name="MiD[]"><br />
    <input type="checkbox" value="6" name="MiD[]"><br />
    <input type="checkbox" value="7" name="MiD[]"><br />
    <input type="checkbox" value="8" name="MiD[]"><br />
    <input type="checkbox" value="9" name="MiD[]"><br />
    <input type="submit"><br />
    </form>
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  7. #7

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    Cool Tnx
    Wayne

Posting Permissions

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



Click Here to Expand Forum to Full Width