Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // view
- <form id="my_form">
- <textarea name="blow[]"></textarea>
- <textarea name="blow[]"></textarea>
- <textarea name="blow[]"></textarea>
- <textarea name="blow[]"></textarea>
- <textarea name="blow[]"></textarea>
- <textarea name="blow[]"></textarea>
- <textarea name="blow[]"></textarea>
- <textarea name="blow[]"></textarea>
- </form>
- // ajax
- type: 'POST',
- data: $('#my_form').serialize()
- // controller
- foreach($_POST as $k => $v) {
- if(count($v) == 8) {
- // $k = "blow"
- // $v = array();
- $this->my_model->insert($k, $v);
- }
- }
- // model
- function insert($id, $txt) {
- $data = array(
- 'id' => $id
- );
- foreach($txt as $index => $value) {
- $index1 = $index+1;
- $data['txt'.$index1] = $value;
- }
- // $data = array(
- // 'id' => $id,
- // 'txt1' => $txt[0],
- // 'txt2' => $txt[1],
- // 'txt3' => $txt[2],
- // 'txt4' => $txt[3],
- // 'txt5' => $txt[4],
- // 'txt6' => $txt[5],
- // 'txt7' => $txt[6],
- // 'txt8' => $txt[7]
- // );
- $this->db->insert('my_table', $data);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement