Jump to content

Recommended Posts

hello.... I'm stuck... I'm trying to populate a check box with a 2d array. I have made three arrays within one array, but when i run it, nothing appears..

here is the code i have used so far:

 

 

<legend>Optional extras</legend>

<optgroup label="Entertainment">
<?php
foreach($car_extras as $car_extras_id => $extras)
{
echo '.$car_extras_id.';
	{
	foreach($extras as $entertainment)
	$i++;
	echo '<input type=checkbox name="options" value="'.$extras.'" id="entertainment'.$num[$i].'"/>';
	echo '<label for ="entertainment'.$num[$i].'">'.$entertainment.'</label><br/>';
	}
}
?>

 

This is the array code

$car_extras = array
("Entertainment"=>array("6 disc DVD changer", "TV function", "DAB digital radio", 
"Loudspeaker system - professional", "Multimedia navigation system"),

"Communication"=>array("Universal remote control", "Voice control", "Navigation system","Head-up display"),

"Safety & Security"=>array("Adaptive headlights", "Night vision with pedestrian recognition", "Run-flat tyres"));

 

Thanks for the help!

Link to comment
https://forums.phpfreaks.com/topic/236649-help-with-checkboxs-with-2d-array/
Share on other sites

The <optgroup> tag is to be used within a <select> list only, eg

<select>
  <optgroup label="Swedish Cars">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
  </optgroup>
  <optgroup label="German Cars">
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
  </optgroup>
</select>

 

You probably want to use a div or fieldset/legend tags maybe?

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.