Solved

Move Items between select boxes

Posted on 2003-11-22
1
302 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
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.

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now