Inserting For each? |
[eluser]Dizza[/eluser]
Hey there, Is there a way to submit a form more times then one? The problem i am having is i have multiple students and each student can be "aanwezig" or "niet aanwezig". Now if i submit the form with the students it will only submit the first student and not the rest. Is there a way to keep submitting until i had al the students inserted? Here a screenshot, maybe it will make more sense! http://cl.ly/2f3U1u1L2D033q3j2M1v Hope someone can help me!
[eluser]Glazz[/eluser]
You can name your form selects like Code: student[student_id_1] In your foreach loop or while loop you change the "student_id_1" to that student id. Hope i make it clear for you, if not, post your view here and i change it for you.
[eluser]Dizza[/eluser]
Here is my view! Sorry for the mess, usually i clean it up after i fixed the entire function The leerling = student! Code: <table id="aanwezigheid"> Thanks!
[eluser]Glazz[/eluser]
I think this should work Code: <?php echo form_dropdown('aanwezigheid[' . $leerlingen['ID'] . ']', $options, ''); ?>
[eluser]Dizza[/eluser]
Ooow sorry, i dont think i explained myself well BUT THANKS I meant that for each student i need to insert a query. The problem that i have is when i submit my form it will only update the first student in my form and not the other students which i get from my foreach loop in my view. So i wanted to know if there is a way to submit the form multiple times so each student is being update. If i submit my form now it will only submit the first one like this Code: INSERT INTO `aanwezigheid` (`llID`, `lesuurID`, `aanwezig`) VALUES ('8', '2', 'niet aanwezig' ) OR is it possible to use the form_dropdown you gave and submit it for each student? BTW i will use your dropdown anyways because its way cleaner thanks!
[eluser]Glazz[/eluser]
You submit the form only once of course, then with the data you get from $_POST you do a foreach. Something like Code: foreach ( $this->input->post('aanwezigheid') as $studentID => $value ) Don't know if it works properly, but i use it this way when i have tabular data and multiple dropdowns or inputs with the same name.
[eluser]Dizza[/eluser]
Thanks im going to try it! If i have any questions i will probably post again haha ThANKS!!
[eluser]Dizza[/eluser]
[quote author="Glazz" date="1339437835"]You submit the form only once of course, then with the data you get from $_POST you do a foreach. Something like Code: foreach ( $this->input->post('aanwezigheid') as $studentID => $value ) Don't know if it works properly, but i use it this way when i have tabular data and multiple dropdowns or inputs with the same name.[/quote] I have a question, probably an easy answer for you, but the how do i get the $value? If i use the <?php echo form_dropdown('aanwezigheid[' . $leerlingen['ID'] . ']', $options, ''); ?> i get an empty array. And what do i post inside the for each loop?
[eluser]Glazz[/eluser]
After you submit your form, try using this code to see what you are exactly getting from the form: Code: var_dump( $this->input->post() ); Code: var_dump( $this->input->post('aanwezigheid') ); Inside the foreach, you place your mysql query, but you need change the values of course, so it will be automatically. |
Welcome Guest, Not a member yet? Register Sign In |