Forums

custom code foreach change values

ideagrup 23 Jul, 2015
Hello,

I have a form with a multiple container it shows 60 rows perfectly.

on submit form is executed a custom code with this sample code:
<?php
$results = array();
foreach ( $form->data['coles'] as $v ) {
$to = $v[co_m_director];
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: ideagrup@yahoo.es" . "\r\n";
mail($to,$subject,$txt,$headers);
}
?>
The code runs perfectly and sends mails perfectly, but I have 2 problems:

Problem 1: I would like show the send progress like this (echo "mail sent to". $to) but only is showing at end of custom code. Is posible to show every row during the process?

Problem 2: I would like to update every row in the database for controlling all mails sending. But if i put update sentence inside of "foreach" i believe that will happend the same.

Can you help me??

Thomas
GreyHead 25 Jul, 2015
Hi Thomas,

1. No, the email sending is being done on the server and nothing is sent back to the browser until the code finishes processing. you could possibly do this using custom code and submitting the form using AJAX but I doubt if it is worth the work involved. If the problem is the long delay you could show a 'Loading' image and/or message.

2. You can add a MySQL query to update a record inside the foreach loop but it will make the process slower and add to the delay. Better to create a results array and add the value of email email submission to that. You can then process that with a single database query at the end of the loop.

Bob
ideagrup 25 Jul, 2015
1. Ok is very very complicated Ajax process for this? Do you have a sample of some similar situation??

2. Yes, Is better to check sending with a field in array.

Thanks Bob
GreyHead 25 Jul, 2015
Hi ideagrup,

1. No, sorry no samples, I've never tried to do anything quite like that.

Bob
This topic is locked and no more replies can be posted.