Re: [PHP] Checking Checkboxes using Arrays
When you perform the test you want to know if the $id is the user's choice and if the user's choice is in the array. Your code reads differently. You are checking to see if $id is the user's choice OR $id is in the array. which would always check the countries in the array. > if(($id == $register_country_of_origin) || (in_array($id, $european_union))) { try this ... > if(($id == $register_country_of_origin) || (in_array($register_country_of_origin, $european_union))) { jim > > $european_union = array('24', '17', '1', '58', '74', '80', >'73', '83', '101', '103', '119', '144', '164', '186', '193', '212'); > print_r($european_union); > > if(mysql_num_rows($europe_result) > 0) { > > while(list($id, $country) = >mysql_fetch_array($europe_result)) { > > if(($id == $register_country_of_origin) || >(in_array($id, $european_union))) { > > echo"\tCLASS=\"pofgreencard\">VALUE=\"$id\" CHECKED> $country\n"; > > } else { > > echo"\tCLASS=\"pofgreencard\">VALUE=\"$id\"> $country\n"; > > } > } > -- Jim Musil - Multimedia Programmer Nettmedia - 212-629-0004 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Checking Checkboxes using Arrays
I'm sorry, your message doesn't make sense... First you say that you want to do what the script is doing, and then you say you don't want it to do that. >i want to select the >countries (check their checkboxes) if they are equal to a particular country >variable I have set or if they appear in an array. >... if i select a country which is not in >the array, it still checks all the boxes of the countires in the array?! Please clarify. -- Jim Musil - Multimedia Programmer Nettmedia - 212-629-0004 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Checking Checkboxes using Arrays
Hi, This is doing my head in. I'm printing out a lot of countires from a db and i want to select the countries (check their checkboxes) if they are equal to a particular country variable I have set or if they appear in an array. My code is: $european_union = array('24', '17', '1', '58', '74', '80', '73', '83', '101', '103', '119', '144', '164', '186', '193', '212'); print_r($european_union); if(mysql_num_rows($europe_result) > 0) { while(list($id, $country) = mysql_fetch_array($europe_result)) { if(($id == $register_country_of_origin) || (in_array($id, $european_union))) { echo"\t $country\n"; } else { echo"\t $country\n"; } } Can anyone give me some tips because if i select a country which is not in the array, it still checks all the boxes of the countires in the array?! I hope this is making sense, I thikn this is what I want ;-) Thanks, Jord -- Jordan Elver Web Developer http://www.theinternetone.co.uk > How do I read MIME files??? Quietly, while pretending to be trapped in an invisible box. :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]