aspirinemaga
aspirinemaga

Reputation: 3947

How to insert multiple rows at once without using inputs in CodeIgniter?

How to insert the datas from a <table> rows into the database without any <input> ?

In CodeIgniter, I have a function where I can generate random users, which are inserted into the <table>...</table> using an AJAX method by clicking on a $('#btnGenerate');

It fills out an empty table with the new table rows (<tr>). Here how it looks like:
Random user generator

Now when I want to save these new rows into the database, I don't know how to proceed. As far as I know, I need to have an array which will be then posted into the form's action: members/form_random for example with the $this->input->post('someInputName');?>. How can I do that if I don't use any <input> tags inside the table ?

Any advice for solution ?

Upvotes: 2

Views: 1253

Answers (1)

Abhik Dey
Abhik Dey

Reputation: 403

When you generate the random users, make sure you store each row in an object array like

var arr = [
    {username:'abc',email:'[email protected]'},
    {username:'def',email:'[email protected]'},
     .
     .
];

And the trigger an onClick event from the Apply,Save Button to an AJAX function and send the array as JSON data to the controller that saves the data.

I think this will sort out your problem..

Upvotes: 3

Related Questions