I am running a PHP function regularly with support of WGET linux command (like CRON). In this case, for every execution, I will take 1500 records from my database, and iterate through foreach loop. Inside the foreach, I need to run a for loop with limit of 20 iterations. Inside the for loop, I will check the current action using switch case.
$samplearray = array('.....'); // Multidimensional array contains 1500 rows
foreach($samplearray as $samplearr)
{
for($s=1;$s<=20;$s++)
{
$step = mysql_query("SELECT steptype FROM steptable WHERE camapign=$samplearr['campaign'] AND currentstep=$s")or die(mysql_error());
$stepdet = mysql_fetch_array($step);
switch($stepdet ['steptype'])
{
case 'email':
// PHP mailer script to send emails
break;
case 'sms':
// Third party URL to send SMS using Curl execution
break;
case 'others':
// DB updations - Mysql Query
break;
// DB updations - Mysql Query
}
}
}
Here, the problem is, if the case contains 'email' or 'sms', duplicates are sending.
For e.g. in 1500 iterations, more than 2500 emails are sent. I don't know where the problem occurs.
Thanks in advance.