![]() |
insert/edit many to one records - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: insert/edit many to one records (/showthread.php?tid=19668) |
insert/edit many to one records - El Forum - 06-15-2009 [eluser]jared4444[/eluser] Hi, I am very new to CI, and MVC (only 2 days). I am really struggling with how to even get started on this issue. Here is what I am doing: I have two tables (simplified) Item ID, itemName (nothing else important here) Size ID, name, itemID, price ex. Item = 1, pizza size = 1, small, 1, 2.00 size = 2, medium, 1, 3.00 size = 3, large, 1, 4.00 So I am building a db with pizza sizes small, medium, and large with associated prices. I know how to make one form and save/edit items, I can also do the same for sizes. I would like to have one form where I can enter an item, then below do the sizes, and have this page reload and be able to validate, but all the examples I see have to do with editing one record at a time. Item Name = _____________ [add size] click add size would bring up Item Name = _____________ Size Name=____________ Size Price=____________ [delete size] [add size] click add size would bring up Item Name = _____________ Size Name=____________ Size Price=____________ [delete size] Size Name=____________ Size Price=____________ [delete size] How would I ever get this started? I don't know how to edit multiple records on the same form, especially when they come from different tables (item, size). Also, if someone were to remove the item name and I had to validate it, what happens to the sizes since they would not be processed by the db? Would I have to save all form variables, and be able to repopulate the form again? As you can see I am pretty clueless with this. Any help would be great! insert/edit many to one records - El Forum - 06-15-2009 [eluser]LeopoldoVettor[/eluser] There are many ways to do this, but i advice you to make a many to many relashionship with pizza and sizes having a associative table to join the pizza and sizes. With this, you can create a dinamic form that have the size_id on the field name and use form_validation library to make its validation easly. Read more about input, form validation and active record classes to make this. Sorry for the poor english. insert/edit many to one records - El Forum - 06-15-2009 [eluser]jared4444[/eluser] [quote author="LeopoldoVettor" date="1245094165"]With this, you can create a dinamic form that have the size_id on the field name and use form_validation library to make its validation easly. [/quote] Thanks, I actually do have an associative table. So I have sizes {id, size}, then the table I showed you which really has sizeid instead of name, then I have an itemtosizemapping table. I was trying to simplify. The example I gave will be enough to get me started though. I am not really looking for help with the table structure though. I can handle that alright. I am having trouble with the dynamic form part. Every example shows how to do one record in one table, the problem I outlined above is much more complicated that that. I still have the same question as above. |