How to insert multiple selected values from dropdown in Codeignitor

I have three fields

CategoryA-->CategoryB -->CategoryC

CategoryA has single value to be stored in Database
CategoryB has multiple values to be stored in Database Table
CategoryC has multiple values to be stored in Database Table

In codeigniter , I m imploding the values of the both CategoryB and CategoryC
before , saving the form data in the model class save function  

Do I need to do something in View  also ...

something like this , add html array :

<select name="pk_id[]" size="10" multiple>

But I m not using name to refer to the dropdown /select but using id to achieve
that .
Puneet AroraFounderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Marco GasiFreelancerCommented:
So, let's me summarize what I guess from your question:

 - you have a view with 3  select and 2 of them allow multiple selection.
 - when the user click submit the form is submitted to a controller method which invokes a model method and perform several actions to put values in the database.
 - You want some effect of the selection be visible in the view

My questions are:

 - what you need to do in view?
 - how do you call controller function which invokes model method, through an Ajax call or through a php submission?

Please, be more descriptive about what you have and about what you want: giving answers when we have to guess the question is really difficult :-)
Julian HansenCommented:
But I m not using name to refer to the dropdown /select but using id to achieve
that .

To post data back using standard submit you would need a name for the input control in order for the data to be sent back.

In the case of a multiple select you need an array - so your name would have to have [] at the end to denote array values.

Unless you are processing your form through AJAX and collecting the data manually - and even then the ideal way would be to name your controls and use something like form.serialize() to get the data - you would need to populate that name field of your select - and in the case of a multi put square brackets at the end to return the array of values.
Puneet AroraFounderAuthor Commented:
Dear Sir ,

The View is basically a form which get the input from a data entry operator to fill business listing .
So each , business is based on Category A--> Category B (Multi Select)-->Category C. (Multi Select)-
So , when the Data Entry operator submits the business listing form .It does stores the values
of all Category plus all fields , but does not multiple values of the Category B (Multi Select)+Category C.
Using Ajax , I have build the dependency between the each of the dropbox .

The Data Model Function Save_Form have a parameter $formdata , I check if has all the form control values
and in case of CategoryB and CategoryC select use function implode  with ',' option .  The controller has set rule and other standard function of codeigniter . And they are working fine . But they are saving single values now of category B& C

Yes , I understand I need to send an array of CategoryB & C Selected  values , But I do not know ? How to ? The syntax and need to do I need to explore or join selected values of CategoryB and C .. But How to ? Question is this ?
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Julian HansenCommented:
But I do not know ? How to ?

The easiest way to do this is to give all your controls names - and your select a name with brackets.

Then use the jQuery .serialize() function to collect the data.

Example here

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Marco GasiFreelancerCommented:
In Julian example, just replace the form action with <controller/method>: the Ajax code will call your method wher you'll can invoke some model method to store values in the database, and return some output to tha ajax function which will can display some result.
If you post here your ajax code and control + model methods involved, I'll can be more specific.
Puneet AroraFounderAuthor Commented:
Dear Sir , I will post in few hours  , out of office for the time being !
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.