What do you mean by best format to store the selected option ? If the value is an integer, have an integer field. If its an alphanumeric, have a varchar field. Is this what you are talking about ?
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
since most people will probably never pick more than a few, it would save space to only have one column.
try this:
<?php
//multi-list boxes post an array of results
//get this array into a single comma-seperated-value string
foreach($_POST['select'] as $key=>$val)
{
//add item as comma-seperated-value
$csv .= $val .',';
}
//trim trailing comma
$csv = rtrim($csv,',');
//INSERT $csv INTO A SINGLE FIELD IN YOUR DATABASE ROW HERE!!!
//you can do the sql HERE...
//end part one!
//later you can sort your comma-seperated-value that you retrieve from the database back into individual elements like so...
//you can do the sql HERE...
//store all individual items in an array
$arrayOfItems = explode(',',$csv);
//build each of your items in a list
foreach($arrayOfItems as $key=>$val)
{
$output .= '<li>' . $val . '</li>';
}
//display output
echo $output;
?>
johnsquibb
Junior Poster in Training
84 posts since Nov 2007
Reputation Points: 14
Solved Threads: 14
Working off the code sample in my earlier post...
Here would be one way to ensure the checkboxes were checked if they had chosen them previously...
//array to hold checkbox options
$checkBoxOptions = array('sentence 1' , 'sentence 2' , 'sentence 3' , 'sentence 4');
//create checkbox output
$cbOut = '';
foreach($checkBoxOptions as $val)
{
//test to see if stored choices match a checkbox value.
if(in_array($val , $arrayOfItems))
{
//stored choice was found, mark this box
$cbOut .= '<input type="checkbox" name="'.$val.'" checked="checked" value="'.$val.'"/><label>' . $val . '</label><br/>';
}
else
{
//choice has not been stored, leave box unchecked
$cbOut .= '<input type="checkbox" name="'.$val.'" value="'.$val.'"/><label>' . $val . '</label><br/>';
}
}
//output checkboxes
echo $cbOut;
johnsquibb
Junior Poster in Training
84 posts since Nov 2007
Reputation Points: 14
Solved Threads: 14