Use same field multiple times? |
[eluser]Joakim_[/eluser]
Once again a newbie question and it might more be a PHP or SQL question. Is it possible to use same field multiple times? I have a class called line, and when the user clicks on add new line link he gets up a new line class which use the same fields but with different ID's. Do I have to manually add these fields in the database, such as firstname1, firstname2 etc. or is there any way to do it automatically? Code: <div class="line"> Any help are very appreciated. Thanks!
[eluser]marcoss[/eluser]
It is quite simple: Code: <div class="line"> now, when you add a new line, just increment the line ID (lines[2] instead of lines[1] and you will get this: Code: <div class="line"> Finally, when you process it, just loop the lines array, Code: <?php
[eluser]Joakim_[/eluser]
Thank you very much for your help. I get an error when I try to submit the form: Message: Array to string conversion and Unknown column 'Array' in 'field list' The Form looks like this: Code: <form action="items/new" method="post"> The items/new function looks like this: Code: $this->db->insert('items', $_POST); Shall I add the if(isset($_POST['lines']... code into the items/new function? I have a row in the database called lines. I assume all details (firstname, lastname and email) are stored in the same database row? How can I then display these details? Sorry for all stupid questions, I'm new into both PHP and CL. Thanks a lot!
[eluser]dbashyal[/eluser]
how about this. if the form always have lines[1][...] Code: if(isset($_POST)) if more fields like lines[1][...] lines[2][...] Code: if(isset($_POST) && is_array($_POST['lines'])) foreach ($_POST['lines'] as $v) i haven't tested though.
[eluser]Joakim_[/eluser]
Thank you very much for your reply. Shall I have firstname, lastname and email also as fields in the database? Or is it enough with "lines"?
[eluser]dbashyal[/eluser]
http://ellislab.com/codeigniter/user-gui...ecord.html says: that code produces INSERT INTO mytable (title, content, date) VALUES ('My Title', 'My Content', 'My Date') so i guess you need those fields in database. plz refer doc. i haven't gone through yet. |
Welcome Guest, Not a member yet? Register Sign In |