|
-
Nov 24th, 2002, 05:07 PM
#1
Thread Starter
Frenzied Member
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
-
Nov 24th, 2002, 05:36 PM
#2
Fanatic Member
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";
?>
-
Nov 24th, 2002, 05:39 PM
#3
Thread Starter
Frenzied Member
OK,
& If i have total gibberish as the value? or?
Or is this takin into account (Can u explain it a little ? )
Tnx
-
Nov 24th, 2002, 05:41 PM
#4
Fanatic Member
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";
?>
-
Nov 24th, 2002, 05:44 PM
#5
Thread Starter
Frenzied Member
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.
-
Nov 24th, 2002, 05:47 PM
#6
Fanatic Member
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>
-
Nov 24th, 2002, 05:51 PM
#7
Thread Starter
Frenzied Member
Cool Tnx
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|