Re: problem with for loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I think Peter is probably right. In the case he is not however, can
 you post a print_r of $multiArray.

 - Craige



 On Fri, May 2, 2008 at 7:24 AM, Peter Ford <pete@xxxxxxxxxxxxx> wrote:
 >
 > Richard Kurth wrote:
 >
 > > Way does my for loop not complete the task if there are 4 emails it only
 > process 3 emails through the foreach loop if there is 3 it only process 2
 > >
 > >    #  Connect up
 > >    $host ="domain.com";
 > >    $port ="110";
 > >    $mailtype = "pop3";
 > >    $mailbox ="INBOX";
 > >    $username ="bounce@xxxxxxxxxx";
 > >    $password ="boat1234";
 > >       $conn = @imap_open("{" . $host . ":" . $port . "/" . $mailtype .
 > "/notls}" . $mailbox, $username, $password);
 > >
 > > $number=imap_num_msg($conn);
 > > for($i = 1; $i <= $number; $i++) {
 > > $file="C:\web\bouncehandler\eml\em$i";
 > > imap_savebody($conn,$file,$i);
 > >
 > >
 > > $file=file_get_contents("C:\web\bouncehandler\eml\em$i");
 > > $multiArray = Bouncehandler::get_the_facts($file);
 > >
 > > $EMAIL = $the['recipient'];
 > > foreach($multiArray as $the){
 > >       switch($the['action']){
 > >       case 'failed':
 > >       $sql="UPDATE contacts SET emailstatus = 'Fatal-Bounced' WHERE
 > emailaddress = '$EMAIL'";
 > >       mysql_query($sql) or die("Invalid query: " . mysql_error());
 > break;
 > >       case 'transient':
 > >       $sql="UPDATE contacts SET emailstatus = 'Bounced' WHERE emailaddress
 > = '$EMAIL'";
 > >       mysql_query($sql) or die("Invalid query: " . mysql_error());
 > >       break;
 > >       case 'autoreply':
 > >       $sql="UPDATE contacts SET emailstatus = 'Bounced' WHERE emailaddress
 > = '$EMAIL'";
 > >       mysql_query($sql) or die("Invalid query: " . mysql_error());
 > >       break;
 > >       default:
 > >       //don't do anything
 > >       break;
 > >       }
 > >   }
 > >
 > > }
 > >
 > >
 > >
 >
 >  I think you need to check the boundary conditions on your loop.
 >  As you write it,
 >
 >
 >         for($i = 1; $i <= $number; $i++)
 >
 >  if $number is 4 then $i will have the values 1,2,3,4.
 >
 >  Perhaps message list is zero-based, and you actually need to count from
 > zero:
 >
 >         for($i = 0; $i < $number; $i++)
 >
 >  so you would get $i to read 0,1,2,3
 >
 >  The manual page doesn't explicitly say the the message number is one-based,
 > and most real programming languages these days use zero-based arrays...
 >
 >  --
 >  Peter Ford                              phone: 01580 893333
 >  Developer                               fax:   01580 893399
 >  Justcroft International Ltd., Staplehurst, Kent
 >
 >
 >
 >  --
 >  PHP General Mailing List (http://www.php.net/)
 >  To unsubscribe, visit: http://www.php.net/unsub.php
 >
 >

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux