Page 1 of 1
getting values in array to populate corresponding Xboxes
Posted: Wed Sep 10, 2008 9:12 am
by glennnphp
i'm having trouble getting this array to populate the selected checkboxes (this almost works, but it only gets the last value, 07 ... ).
Code: Select all
$offering = $_POST['highest_deg']; //returns the selected values, "03,07"
foreach($offering as $x) {
$x... ;
}
<input type="checkbox" name="highest_deg[]" value="03"<?php echo ($x == 03 ? " CHECKED" : ""); ?>
<input type="checkbox" name="highest_deg[]" value="04"<?php echo ($x == 04 ? " CHECKED" : ""); ?>
<input type="checkbox" name="highest_deg[]" value="05"<?php echo ($x == 05 ? " CHECKED" : ""); ?>
<input type="checkbox" name="highest_deg[]" value="04"<?php echo ($x == 06 ? " CHECKED" : ""); ?>
<input type="checkbox" name="highest_deg[]" value="05"<?php echo ($x == 07 ? " CHECKED" : ""); ?>
could someone kindly show me how to populate a group of checkboxes from the array i have...?
i appreciate it much.
GN
Re: getting values in array to populate corresponding Xboxes
Posted: Wed Sep 10, 2008 9:20 am
by marcth
Code: Select all
<?php
if(!isset($_POST['highest_deg'])) {
$_POST['highest_deg'] = array();
}
?>
Code: Select all
<input type="checkbox" name="highest_deg[]" value="03"<?php echo in_array('03', $_POST['highest_deg']) ? ' checked="checked"' : ''); ?> />
<input type="checkbox" name="highest_deg[]" value="04"<?php echo in_array('04', $_POST['highest_deg']) ? ' checked="checked"' : ''); ?> />
<input type="checkbox" name="highest_deg[]" value="05"<?php echo in_array('05', $_POST['highest_deg']) ? ' checked="checked"' : ''); ?> />
<input type="checkbox" name="highest_deg[]" value="06"<?php echo in_array('06', $_POST['highest_deg']) ? ' checked="checked"' : ''); ?> />
Re: getting values in array to populate corresponding Xboxes
Posted: Wed Sep 10, 2008 9:30 am
by glennnphp
awesome, thanks much
Re: getting values in array to populate corresponding Xboxes
Posted: Wed Sep 10, 2008 9:39 am
by glennnphp
"Parse error: syntax error, unexpected ')', expecting ',' or ';'... " - can't find any bad syntax in this first input...
marcth wrote:Code: Select all
<?php
if(!isset($_POST['highest_deg'])) {
$_POST['highest_deg'] = array();
}
?>
Code: Select all
<input type="checkbox" name="highest_deg[]" value="03"<?php echo in_array('03', $_POST['highest_deg']) ? ' checked="checked"' : ''); ?> />
Parse error: syntax error, unexpected ')', expecting ',' or ';'
<input type="checkbox" name="highest_deg[]" value="04"<?php echo in_array('04', $_POST['highest_deg']) ? ' checked="checked"' : ''); ?> />
<input type="checkbox" name="highest_deg[]" value="05"<?php echo in_array('05', $_POST['highest_deg']) ? ' checked="checked"' : ''); ?> />
<input type="checkbox" name="highest_deg[]" value="06"<?php echo in_array('06', $_POST['highest_deg']) ? ' checked="checked"' : ''); ?> />
Re: getting values in array to populate corresponding Xboxes
Posted: Wed Sep 10, 2008 9:46 am
by marcth
There you go.
Code: Select all
<?php
if(!isset($_POST['highest_deg'])) {
$_POST['highest_deg'] = array();
}
?>
Code: Select all
<input type="checkbox" name="highest_deg[]" value="03"<?php echo in_array('03', $_POST['highest_deg']) ? ' checked="checked"' : ''; ?> />
<input type="checkbox" name="highest_deg[]" value="04"<?php echo in_array('04', $_POST['highest_deg']) ? ' checked="checked"' : ''; ?> />
<input type="checkbox" name="highest_deg[]" value="05"<?php echo in_array('05', $_POST['highest_deg']) ? ' checked="checked"' : ''; ?> />
<input type="checkbox" name="highest_deg[]" value="06"<?php echo in_array('06', $_POST['highest_deg']) ? ' checked="checked"' : ''; ?> />
Re: getting values in array to populate corresponding Xboxes
Posted: Wed Sep 10, 2008 9:54 am
by glennnphp
beautiful thanks again
marcth wrote:There you go.
Code: Select all
<?php
if(!isset($_POST['highest_deg'])) {
$_POST['highest_deg'] = array();
}
?>
Code: Select all
<input type="checkbox" name="highest_deg[]" value="03"<?php echo in_array('03', $_POST['highest_deg']) ? ' checked="checked"' : ''; ?> />
<input type="checkbox" name="highest_deg[]" value="04"<?php echo in_array('04', $_POST['highest_deg']) ? ' checked="checked"' : ''; ?> />
<input type="checkbox" name="highest_deg[]" value="05"<?php echo in_array('05', $_POST['highest_deg']) ? ' checked="checked"' : ''; ?> />
<input type="checkbox" name="highest_deg[]" value="06"<?php echo in_array('06', $_POST['highest_deg']) ? ' checked="checked"' : ''; ?> />