juselliott Posted October 29, 2009 Share Posted October 29, 2009 Hi I have a field stored in a table that contains regions in the UK separated by commas. There could be any number of pieces held in this field from 1-12, based upon the users specified operating region (i.e. they could operate in multiple regions). I have then created a form with 12 check boxes, 1 for each possible region they could have specified. I need to automatically tick the relevant box for each region they have specified (i.e. each piece of data held in the field). Is this doable? I have tried experimenting with explode() but cannot figure out to this information to specific whether a check box should be ticked by default. Thanks Link to comment https://forums.phpfreaks.com/topic/179473-solved-using-explode-to-fill-in-checkboxes/ Share on other sites More sharing options...
priti Posted October 29, 2009 Share Posted October 29, 2009 yes this is doable and for checked checkbox you simple needs to write something extra as follow if(userregion == fromdbregion) { <INPUT TYPE=CHECKBOX NAME="region" checked >regionname<BR> } else { <INPUT TYPE=CHECKBOX NAME="region">regionname<BR> } modify this as per you requirement. Regards Link to comment https://forums.phpfreaks.com/topic/179473-solved-using-explode-to-fill-in-checkboxes/#findComment-946951 Share on other sites More sharing options...
scvinodkumar Posted October 29, 2009 Share Posted October 29, 2009 <?php $allregion = array('r1','r2','r3',....,'r12'); //store ur region like this. $region = 'r1,r2,r3'; //get the values from the db $region_explode = explode(",",$region);//make it array using explode for($i=0;$i<12;$i++) { if(in_array($allregion[$i],$region_explode)) echo "<input type='checkbox' name='region' value='".$allregion[$i]."' checked='checked'>"; else echo "<input type='checkbox' name='region' value='".$allregion[$i]."'>"; } ?> Link to comment https://forums.phpfreaks.com/topic/179473-solved-using-explode-to-fill-in-checkboxes/#findComment-946954 Share on other sites More sharing options...
juselliott Posted October 29, 2009 Author Share Posted October 29, 2009 genius! worked perfectly, many thanks. Link to comment https://forums.phpfreaks.com/topic/179473-solved-using-explode-to-fill-in-checkboxes/#findComment-946992 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.