XML XHR Emails

#1
[eluser]fuchong[/eluser]
Hello, I'm currently building a system that takes in an array of emails and sends it to my own library, then my own xmlxhr_server controller. This controller then sends the array to my model where I use a foreach and an embedded foreach to grab information and store it into the db. I was able to get the first foreach to work, but now that I'm adding my embedded foreach I cannot access my data using it.

This is the code that builds my array and sends it to my built library, which sends it to the

$emailarray = array(

array(
// Param 1
array(
'fromaddress' => 'example@hotmail.com',
'toaddress' => 'bill@hotmail.com',
'bccaddress' => null,
'subject' => 'this is the second subject of the email',
'emailtext' => 'this is the text of the email',
'htmltext' => null,
'requestedapp' => 'Test Application',
'priority' => 3,
'attachments' =>array(

array(
'img' => 'Money',
'type' => 'jpg',
),
'struct',

array(
'img' => 'Foo',
'type' => 'Bar',
),
'struct',
)


),
'struct'
),
'struct'

),


);
$this->load->library('emailqueue');
$stuff = $this->emailqueue->queueemails($emailarray);


The data gets sent correctly and my model has the array that I send. The problem I have is when I foreach through my array in my model I cannot get the correct information from 'attachments'.

function addemails($emailarray)
{
foreach($emailarray as $e)
{
if(isset($e['attachments']) && $e['attachments'] != null)
{
// my embedded foreach
foreach($e['attachments'] as $w)
{
$insrt['attchdata'] = $w['img'];
$insrt['extension'] = $w['type'];
$this->db->insert('attachments', $insrt);
}
}

$insert = array('toaddress' => $e['toaddress'],
'fromaddress' => $e['fromaddress'],
'subject' => $e['subject'],
'requestedapp' => $e['requestedapp'],
'priority' => $e['priority'],
'attempts' => 0,
'logdate' => date('Y-m-d H:iConfused'));

$this->db->insert('email', $insert);

}


}


The problem here is that I can't get my embedded foreach to work correctly. The way that the embedded foreach is written it runs through twice and grabs me the first character 'M' from the first 'img' index and 'j' from the first 'type' index. So in my db I have two new rows, where the type is filled with 'j' and img is filled with 'M'. I cannot get this embedded foreach to realize that there is more that one array. All it sees is the first array and its two elements.

Thanks in advance for the help!

#2
[eluser]kirtan.n[/eluser]
you need to embed one more foreach

function addemails($emailarray)
{
foreach($emailarray as $e)
{
foreach($e as $e2)//need one more
{
if(isset($e2[‘attachments’]) && $e2[‘attachments’] != null)
{
// my embedded foreach
foreach($e2[‘attachments’] as $w)
{
$insrt[‘attchdata’] = $w[‘img’];
$insrt[‘extension’] = $w[‘type’];
$this->db->insert(‘attachments’, $insrt);
}
}

$insert = array(‘toaddress’ => $e[‘toaddress’],
‘fromaddress’ => $e[‘fromaddress’],
‘subject’ => $e[‘subject’],
‘requestedapp’ => $e[‘requestedapp’],
‘priority’ => $e[‘priority’],
‘attempts’ => 0,
‘logdate’ => date(‘Y-m-d H:iConfused’));

$this->db->insert(‘email’, $insert);
}
}


}

#3
[eluser]InsiteFX[/eluser]
Please you the forums POST REPLY and Code Tags!
When submitting code on the forums.

Thank you
InsiteFX


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.