Checking Checkboxes using Arrays

From: Date: Thu, 06 Dec 2001 15:15:22 +0000
Subject: Checking Checkboxes using Arrays
Groups: php.general 
Request: Send a blank email to php-general+get-76890@lists.php.net to get a copy of this message
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<TD WIDTH=\"50%\" CLASS=\"pofgreencard\"><INPUT TYPE=\"checkbox\" NAME=\"country_id[]\" VALUE=\"$id\" CHECKED> $country</TD>\n"; } else { echo"\t<TD WIDTH=\"50%\" CLASS=\"pofgreencard\"><INPUT TYPE=\"checkbox\" NAME=\"country_id[]\" VALUE=\"$id\"> $country</TD>\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. :)

« previous php.general (#76890) next »