⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Insert same form-data repeatly depending on range



tofayelahmed
  • profile picture
  • Member

Posted 29 March 2012 - 06:36 AM

Hello,
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.

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 29 March 2012 - 06:40 AM

I don't understand!
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?

tofayelahmed
  • profile picture
  • Member

Posted 29 March 2012 - 07:08 AM

thanx for your quick reply.

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.

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 29 March 2012 - 07:12 AM

You have to use callback_after_insert and callback_after_update . I am sorry that I don't have an example for this. It works with a similar way as callback_before_insert ( http://www.grocerycrud.com/examples/callback_before_insert_example )
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;

}

tofayelahmed
  • profile picture
  • Member

Posted 29 March 2012 - 09:18 AM

Thanx for your reply.
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.

tofayelahmed
  • profile picture
  • Member

Posted 01 April 2012 - 13:09 PM

I don't understand! How use callback_after_insert and callback_after_update in this problem?

xxaxxo
  • profile picture
  • Member

Posted 02 April 2012 - 04:55 AM

Are you familiar with php programming ? ... if no - you are not supposed to modify the CRUD and you should go watch some tutorials on programing , if yes - then it's simple as that :
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

tofayelahmed
  • profile picture
  • Member

Posted 02 April 2012 - 10:35 AM

Thanx web-johnny and xxaxxo.

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;
}


mryasir
  • profile picture
  • Member

Posted 12 April 2012 - 05:08 AM

I like grocery crud , but its limited to very sort of actions .. e.g. how to do this.
--------------------------------------------------------
| Title1 | Title2 | Title 3 | Title 4 |
--------------------------------------------------------
| input1 | selecta1| selectb1 | selectc1 |
| input2 | selecta2| selectb2 | selectc2 |
| input3 | selecta3| selectb3 | selectc3 |
| input4 | selecta4| selectb4 | selectc4 |
------------------------------------------ SUBMIT

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 12 April 2012 - 17:50 PM

Yes this functionality is not yet available.

If you think that it is limited why you don't try to extend it?