Forum Moderators: coopster

Message Too Old, No Replies

Handeling checkboxes with same name?

Can I post checkbox values as an array?

         

Twixly

9:54 am on Apr 28, 2005 (gmt 0)

10+ Year Member



Hello!

Just wondering if there´s any way to post a number of checkboxes values as an array?

i.e

while ($customer = mysql_fetch_array($result, MYSQL_BOTH))
{
echo "<INPUT TYPE='CHECKBOX' NAME='ALTERTHIS' VALUE='".$customer[0]."'><BR>";
}

Will create a list of checkboxes with same NAME, but different VALUES that it gets from database. Problem is it seems to reset the VALUE of NAME in each loop, instead of creating an ARRAY of "ALTERTHIS" values that I need to access..

I could give each checkbox an uniqe name, but I never know which ones will be set or what values to alter in the database in next page..

Hope you understand what I mean?

ncreegan

10:13 am on Apr 28, 2005 (gmt 0)

10+ Year Member



while ($customer = mysql_fetch_array($result, MYSQL_BOTH)) 
{
echo "<INPUT TYPE='CHECKBOX' NAME='checkboxname[]' VALUE='".$customer[0]."'><BR>";
}

will add 'values' to array checkboxname[], then just treat it like an array to get the data out on the submission page.

anshul

10:14 am on Apr 28, 2005 (gmt 0)

10+ Year Member



Use a ( counter ) growing variable like $customer[$i]
increment $i then.

Twixly

11:03 am on Apr 28, 2005 (gmt 0)

10+ Year Member



Thank you

Twixly

11:36 am on Apr 28, 2005 (gmt 0)

10+ Year Member



Nah that didnt work.. here´s the whole actuall code, maybe I´ve missed something else.

echo "<FORM METHOD='POST' ACTION='submitted.php'>";
while ($kunder = mysql_fetch_array($result, MYSQL_BOTH)) {
echo "<TR ALIGN='CENTER' BGCOLOR='black'>";
echo "<TD BGCOLOR='BLACK'>";
echo $kunder[1];
echo "</TD>";
echo "<TD BGCOLOR='#B0C4DE' WIDTH='70%'>";
echo "<A HREF='index.php?page=se_kund&kundid=".$kunder[0]."'>",$kunder[2],"</A>";
echo "</TD><TD>";
echo $kunder[3];
echo "</TD><TD>";
echo $kunder[13];
echo "</TD>";

echo "<TD>";
echo "<INPUT TYPE='CHECKBOX' NAME='alter[]' VALUE='".$kunder[0]."'>";
echo "</TD></TR>";

}
echo "<INPUT TYPE='SUBMIT' VALUE='OK'></FORM>";

ncreegan

11:41 am on Apr 28, 2005 (gmt 0)

10+ Year Member



how are you trying to access alter[] in submitted.php?

Twixly

11:45 am on Apr 28, 2005 (gmt 0)

10+ Year Member



nvm seems I missed something else, lol. It works! Thanks again and sorry bout the repost ;)