Patelkiranat1983′s Weblog

Just another WordPress.com weblog

Multi Select Box to MySql DB Table

<?
//Create multi select box, pulling data from db
$sql = “SELECT id,name FROM table ORDER BY name ASC”;
$result = mysql_query($sql);

if($result && mysql_num_rows($result)>0)
{
?>
<select name=“id[]” size=5 multiple><option value=0 selected>Select Name…</option>
<?
for($i=0;$i<mysql_num_rows($result);$i++)
{
$arr=mysql_fetch_array($result);
echo “<option value=” . $arr[‘id’] . “>”.$arr[‘name’];
}
echo “</select>”;
}else
echo “No Names in DB”;
?>

<?
//when multi select is submitted from form, this part processes it

$id = $_POST[‘id’];

foreach ($_POST[‘id’] as $id)

$result_system = mysql_query(“INSERT INTO diff_table (diff_id,id) VALUES (’$diff_id’,’” . $id . “‘)”)or die(“Insert Error: “.mysql_error());

?>

August 9, 2007 - Posted by | Uncategorized

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.