Insert same form-data repeatly depending on range
- Single Page
Posted 29 March 2012 - 06:36 AM
I am new user in grocery crud. Recently I faces a problem for developing my project by grocery crud.
I want to insert same form data repeatly depending on range..Such as
My table name is "[b]book_library[/b]" and fields are[b] id,subject,title,accession_no.[/b]
If I have 300 books which subject and title are same but different in accession number(13000-13300).
How can I insert these 300 books at a time.
[b]Note:[/b] accession number maitains a sequence.
Please help emergency.
Posted 29 March 2012 - 06:40 AM
How grocery CRUD could help you with this? You just need a custom query for this.
Can you be more specific about what do you want to do with an example of a form?
Posted 29 March 2012 - 07:08 AM
My form example
----------------------------------------------
1. name
2. email
3. range(like : 100-110)
I want to insert in database like
------------------------------------------------------
ld name email range
---- --------- --------- ----------
1 rony rony@gmail.com 101
2 rony rony@gmail.com 102
-------
-------
10 rony rony@gmail.com 110
*where name and email are same .Only range will increment depends on range.
Posted 29 March 2012 - 07:12 AM
The only difference is that you have the primary key value at the callback, so at the example it will be :
function your_callback($post_array,$primary_key)
{
$this->db->....
return true;
}
Posted 29 March 2012 - 09:18 AM
I attach some image. I think this will clear my problem.
[img]http://mysoftheaven.net/HTML/add_image.jpg[/img]
Here '[b]Accession first[/b]' and '[b]Accession last[/b] ' are added by '[b]callback_add_field[/b]' function.
Now, if Accession first = 120 and Accession last= 125.
I want the output of my table as like as below image
[img]http://mysoftheaven.net/HTML/table.jpg[/img]
Note: Here subject, title and author are same. Only accession_no is increment depends on [b]Accession first [/b]and [b]Accession last[/b] field.
Please don't angry for my reply.
I will wait for your reply.
Posted 01 April 2012 - 13:09 PM
Posted 02 April 2012 - 04:55 AM
1. make a callback_after_insert function
2. run a simple loop(from the first to the last accession num) with the data and check (and change) every accession number while doing a manual insert in your db.
3. come back to this forum and thank web-johnny for the CRUD
Posted 02 April 2012 - 10:35 AM
My problem is solved.
My code is here:
function book_set()
{
$this->grocery_crud->set_table('tb_book');
$this->grocery_crud->fields('subject','accession_no','acc_first','acc_last');
$this->grocery_crud->callback_add_field('acc_first',array($this,'add_field_callback_1'));
$this->grocery_crud->callback_add_field('acc_last',array($this,'add_field_callback_2'));
$this->grocery_crud->callback_before_insert(array($this,'repeat_insert'));
$this->grocery_crud->change_field_type('accession_no','hidden');
$output = $this->grocery_crud->render();
$this->lib_output($output);
}
function repeat_insert($post_array)
{
$acc_first = $post_array['acc_first'];
$acc_last = $post_array['acc_last'];
$subject = $post_array['subject'];
$post_array['accession_no'] = $acc_first;
for($i=$acc_first + 1; $i<=$acc_last; $i++)
{
$data = array();
$data['subject'] = $subject;
$data['accession_no'] = $i;
$data['acc_first'] = $acc_first;
$data['acc_last'] = $acc_last;
$this->db->insert('tb_book',$data);
}
return $post_array;
}
Posted 12 April 2012 - 05:08 AM
--------------------------------------------------------
| Title1 | Title2 | Title 3 | Title 4 |
--------------------------------------------------------
| input1 | selecta1| selectb1 | selectc1 |
| input2 | selecta2| selectb2 | selectc2 |
| input3 | selecta3| selectb3 | selectc3 |
| input4 | selecta4| selectb4 | selectc4 |
------------------------------------------ SUBMIT
Posted 12 April 2012 - 17:50 PM
If you think that it is limited why you don't try to extend it?