Multiple select

Hello
I have this code which I can only select 1 category.
How I can do it to select multiple categories?

<p>
					<b style="margin: auto;">Category:</b>
					<select style="margin: auto;" name="Form[category_id]">
						<?php foreach($categories as $category ) {
							if($deal[category_id]==$category[id])
								print "<option selected value='$category[id]'>$category[name]</option>";
							else
								print "<option value='$category[id]'>$category[name]</option>";
						} ?>
					</select>
				</p>

You were close, I personally would had chosen to use checkboxes.

I called this file select_category.php:

[php]<?php
$category = array(‘Explorer’, ‘Taurus’, ‘Fusion’, ‘Focus’, ‘F-150’, ‘Escape’, ‘Pinto’);
if ( isset($_POST[‘submit’]) && $_POST[‘submit’] == ‘Submit’ ) {
$mySelection = ‘’;
foreach ( $_POST[‘cars’] as $value ) {
$mySelection .= $value . ’ ';
}
}
?>

Select Multiple Categories

You have selected <?php echo (isset($mySelection)) ? $mySelection : 'Nothing'; ?>

<?php foreach ( $category as $value ) { echo '' . $value . '' . PHP_EOL; } ?>

Hold down the Ctrl (windows) / Command (Mac) button to select multiple options.

[/php]

I was bored. ;D

[php]<?php
$category = array(‘Explorer’, ‘Taurus’, ‘Fusion’, ‘Focus’, ‘F-150’, ‘Escape’, ‘Pinto’);
if ( isset($_POST[‘submit’]) && $_POST[‘submit’] == ‘Submit’ ) {
$mySelection = ‘’;
foreach ( $_POST[‘cars’] as $value ) {
$mySelection .= $value . ’ ';
}
}
?>

Select Multiple Categories .myBox { width: 670px; height: 500px; background-color: lightblue; box-sizing: border-box; padding: 20px; margin: 0 auto; } .myInstructions, .myMsg { font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif; font-size: 1.2rem; line-height: 1.5; } .myBlock { display: inline-block; vertical-align: top; overflow: hidden; border: #2e2e2e solid 1px; } .myBlock select { height: 260px; font-family: Arial, Helvetica, sans-serif; font-size: 1.2rem; padding: 10px; margin:-5px -25px -5px -7px; } input[type=submit] { display: block; width: 100px; height: 25px; font-size: 1.2rem; margin-top: 20px; } .selections { color: green; font-weight: bold; text-transform: uppercase; }
<?php foreach ( $category as $value ) { echo '' . $value . '' . PHP_EOL; } ?>

Hold down the Ctrl (windows) / Command (Mac) button to select multiple options.

You have selected: <?php echo (isset($mySelection)) ? $mySelection : 'Nothing'; ?>

[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service