sarahmx
07-29-2013, 03:47 AM
Hello DD
im a php newbie
i need some help with this multiselect transfer code..the code is working.. i just have problem in figuring on how to add/update/delete data to mysql
a. when user add in any value from select1 to select2 and click submit..it will insert data to mysql
b. else when user remove any value from select2 to select 1, it will update/delete in database
i have two tables unit and user
unit is to store the list of unit
user is to when data will be insert/update/delete
<html>
<head>
<script src='http://code.jquery.com/jquery-1.9.1.js'></script>
<script type="text/javascript">
$().ready(function() {
$('#add').click(function() {
return !$('#select1 option:selected').remove().appendTo('#select2');
});
$('#remove').click(function() {
return !$('#select2 option:selected').remove().appendTo('#select1');
});
});
</script>
<style type="text/css">
a {
display: block;
border: 1px solid #aaa;
text-decoration: none;
background-color: #fafafa;
color: #123456;
margin: 2px;
clear:both;
}
div {
float:left;
text-align: center;
margin: 10px;
}
select {
width: 100px;
height: 80px;
}
</style>
</head>
<body>
<div>
<form action="insert.php" method="post">
<?php
include "connect.php";
echo "<select id='select1' multiple>";
$result = mysql_query("SELECT * FROM unit ORDER BY id ASC");
while($row = mysql_fetch_array($result))
{
$list=$row['list_unit'];
echo "<option value='$nama'>$list</option>";
}
echo "</select>";
?>
<a href="#" id="add">add >></a>
</div>
<div>
<select multiple id="select2"></select>
<a href="#" id="remove"><< remove</a>
</div>
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
im a php newbie
i need some help with this multiselect transfer code..the code is working.. i just have problem in figuring on how to add/update/delete data to mysql
a. when user add in any value from select1 to select2 and click submit..it will insert data to mysql
b. else when user remove any value from select2 to select 1, it will update/delete in database
i have two tables unit and user
unit is to store the list of unit
user is to when data will be insert/update/delete
<html>
<head>
<script src='http://code.jquery.com/jquery-1.9.1.js'></script>
<script type="text/javascript">
$().ready(function() {
$('#add').click(function() {
return !$('#select1 option:selected').remove().appendTo('#select2');
});
$('#remove').click(function() {
return !$('#select2 option:selected').remove().appendTo('#select1');
});
});
</script>
<style type="text/css">
a {
display: block;
border: 1px solid #aaa;
text-decoration: none;
background-color: #fafafa;
color: #123456;
margin: 2px;
clear:both;
}
div {
float:left;
text-align: center;
margin: 10px;
}
select {
width: 100px;
height: 80px;
}
</style>
</head>
<body>
<div>
<form action="insert.php" method="post">
<?php
include "connect.php";
echo "<select id='select1' multiple>";
$result = mysql_query("SELECT * FROM unit ORDER BY id ASC");
while($row = mysql_fetch_array($result))
{
$list=$row['list_unit'];
echo "<option value='$nama'>$list</option>";
}
echo "</select>";
?>
<a href="#" id="add">add >></a>
</div>
<div>
<select multiple id="select2"></select>
<a href="#" id="remove"><< remove</a>
</div>
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>