?
Solved

Appending multi-select box to database

Posted on 2005-03-22
5
Medium Priority
?
191 Views
Last Modified: 2012-03-15
A user may select a multiple number of these options within a single submit, each should be concatinated with the existing value for that field. I won't know how many selections they may make ahead of time. Load into an array?

Add Keywords: <select name="keywordparam" size="25" multiple>
            <option value="1">auditory</option>
            <option value="2">boundary</option>
            <option value="3">buildings</option>
            <option value="4">cadastre</option>
            <option value="5">climate</option>
            <option value="6">common</option>
            <option value="7">communications</option>
            <option value="8">cultural</option>
            <option value="9">demographics</option>
            <option value="10">ecology</option>
            <option value="11">environmental_hazards</option>
            <option value="12">flora</option>
            <option value="13">future_projects</option>
            <option value="14">geodetic</option>
            <option value="15">geology</option>
            <option value="16">hydrography</option>
            <option value="17">improvement</option>
            <option value="18">land_status</option>
            <option value="19">landform </option>
            <option value="20">military_operations</option>
            <option value="21">olfactory</option>
            <option value="22">soil</option>
            <option value="23">transportation</option>
            <option value="24">utilities</option>
            <option value="25">visual</option>
        </select>


Then send it to oracle like:

update table a
   set myfield = myfield || 'some new text'
 where ....

??
0
Comment
Question by:dprasad
[X]
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
  • 4
5 Comments
 
LVL 32

Expert Comment

by:Batalf
ID: 13600730
Make it an array

<select name="keywordparam[]" size="25" multiple>

Then loop through the array on the server

if(isset($_POST['keywordparam'])){
    for($no=0;$no<count($_POST['keywordparam']);$no++){
        echo $_POST['keywordparam'][$no]."<br>";
        // DO YOUR UPDATED HERE
    }


}
0
 
LVL 32

Expert Comment

by:Batalf
ID: 13600793
And you shouldn't concat the values into one single field in your database.

To protect your self from future problems, create a new table with a reference to your table above

create table paramList(
tableaID number(11) references tablea on delete cascade,
paramID number(11) references param on delete cascade,
userID number(11) references userTable on delete cascade);

where tableaID is a reference to your table above and
paramID is a reference to the table where your params are located and


Then you could update your values like this:

// Step 1 -> delete existing params for this user
$query="delete from paramList where tableaID='<whatever>'";

// Step 2 insert new values
if(isset($_POST['keywordparam'])){
    for($no=0;$no<count($_POST['keywordparam']);$no++){
        $query="insert into paramList(tableaID,paramID)values('<whatever>','".$_POST['keywordparam'][$no]."')";
    }
}

0
 
LVL 32

Expert Comment

by:Batalf
ID: 13600800
create table paramList(
tableaID number(11) references tablea on delete cascade,
paramID number(11) references param on delete cascade,
userID number(11) references userTable on delete cascade);

should be

create table paramList(
tableaID number(11) references tablea on delete cascade,
paramID number(11) references param on delete cascade);

userID isn't needed since it's the same as tableaID. Forgot to remove that line from the comment.
0
 

Author Comment

by:dprasad
ID: 13601315
yeah it is a bad idea to concatenate like this, will have to run it by the database guys, which could take a while unfortunately
0
 
LVL 32

Accepted Solution

by:
Batalf earned 2000 total points
ID: 13601393
Until then, you could get the the values from the selectbox concatinated like thsi:

if(isset($_POST['keywordparam'])){
    $values = implode(",",$_POST['keywordparam']);
}

now, $value will look like this

"1,2,5"

all depending on the ones the users selected
0

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

771 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