Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Move Items between select boxes

Posted on 2003-11-22
1
305 Views
Last Modified: 2012-08-13
I have two select boxes.  The first is populated from PHP:

$query="SELECT page_permissions.page_id,pages.page_name FROM page_permissions INNER JOIN pages ON page_permissions.page_id = pages.page_id WHERE page_permissions.user='" . $_SESSION['username'] . "'";

$result1 = mysql_query($query);
while($row = mysql_fetch_array($result1))
{
    $toprint="<option value=\"$row[page_id]\">$row[page_name]\n";
    print($toprint);
}


What I want to do is have two buttons, a "->" that will place the selected element from the first box into the second box and "<-" that will remove the item selected in the second box.  Then, once the user is done adding elements into the second select box, I want to INSERT those values into my MySQL database using PHP.  I have been strugging with this for about 8 hours now and realized it was time to ask for help.  I'm having all kinds of issues with this (I can't get multiple 'submit' buttons to work without reloading the page wrong, etc.).  Basically, I'm starting out in this and it's my first web development experience and it's not treating me well.  I realize this is a question with a huge scope, so I made it worth alot of points and I can split them if you dont' have time to answer all the issues right at once.

Thanks ahead of time for your help.

Chad
0
Comment
Question by:mistaeverly
1 Comment
 
LVL 13

Accepted Solution

by:
lozloz earned 250 total points
ID: 9806301
first you want to be doing this through javascript i think:

http://javascript.internet.com/forms/form-swapper-2.html

that seems to be the script you want. all you want to do there is replace the name="list1" for name="items[]", replace all the options with your PHP query above, and have a submit button point to a page to do the processing. then your processing page (could be the same page) will just do:

foreach($_POST["items"] as $key => $val) {
  $query = "INSERT INTO table (column1, column2) VALUES ('$key', '$val')";
  $result = mysql_query($query) or die(mysql_error());
}

if you need any more help then ask away

loz
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question