Results 1 to 2 of 2

Thread: help with multi select transfer code

  1. #1
    Join Date
    Jan 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default help with multi select transfer code

    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


    PHP Code:

    <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 &gt;&gt;</a>
     </div>
     <div>
      <select multiple id="select2"></select>
      <a href="#" id="remove">&lt;&lt; remove</a>
     </div>
     
     <input type="submit" name="submit" value="Submit" />
     </form>
    </body>
    </html>

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by sarahmx View Post
    when user add in any value from select1 to select2 and click submit..it will insert data to mysql
    You'll need to process the data submitted by the form and use it to update your database.

    Quote Originally Posted by sarahmx View Post
    else when user remove any value from select2 to select 1, it will update/delete in database
    This won't happen unless you submit the form (whether by clicking the submit button, or another method, such as AJAX). You need to get the data to your insert.php script.

    ...speaking of
    Quote Originally Posted by sarahmx View Post
    HTML Code:
     <form action="insert.php" method="post">
    Where is your insert.php script? You need to post the code you're asking for help with.

    --------------------------------------------------
    # If at all possible, you should avoid using the mysql_* functions. #
    Existing code should be updated to avoid performance and security problems.
    Quote Originally Posted by php.net (official PHP website)
    Warning
    This extension is deprecated as of PHP 5.5.0, and is not recommended for writing new code as it will be removed in the future. Instead, either the mysqli or PDO_MySQL extension should be used. See also the MySQL API Overview for further help while choosing a MySQL API.

Similar Threads

  1. Select id in multi varchar field
    By huinchaman in forum MySQL and other databases
    Replies: 8
    Last Post: 02-11-2013, 03:03 PM
  2. multi-select open file
    By regicidedelferoz in forum JavaScript
    Replies: 3
    Last Post: 07-06-2011, 05:15 AM
  3. Transfer code
    By TawannaP in forum JavaScript
    Replies: 2
    Last Post: 02-14-2005, 08:49 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •