foreach in mail |
[eluser]E303[/eluser]
I have created a small order form that once completed gets emailed. The problem I have is that when I try to run a foreach loop to display the items I get an unexpected T_FOREACH error. This is my model Code: function mailOrder()
[eluser]Pascal Kriete[/eluser]
You're not printing anything from the foreach. Why don't you just do the foreach outside the e-mail. Code: $items;
[eluser]E303[/eluser]
Thanks, it seems to have worked. Now the script runs however no email is sent. I don't get any errors or anything like that. Any ideas
[eluser]E303[/eluser]
Just quickly, the email code is now like this: Code: foreach($row1 as $item_row) However in the email the $items prints out the number 44 I have been able to work out that the ordered_items.id is 4 and the cost of the item is 42.50 but they are the only two 4's I can find. Any idea what is going wrong?
[eluser]Seppo[/eluser]
row1 is actually a row, not an array of rows, so in the foreach $item_row have the row data, not an array.... Try replacing this Code: $row1 = $product_data->row();
[eluser]E303[/eluser]
thanks for the reply. I have done that at that is how i get this 44?
[eluser]Seppo[/eluser]
$row1 contains array('id' => 4, 'col1' => 'something', 'col2' => 'something', /* ... */ 'price' => 42.50); Then, on the foreach, $item_row has 4 the first time, 'something' on the second... and 42.50 on the last one. Then, $items only cares about the last one (because it is being fully rewritten on each loop), and the last one should be 42.50, you are casting it as string and taking the first character when you try to use it as an array... It's an odd PHP behaviour
[eluser]tonanbarbarian[/eluser]
try this Code: $items = ''; the problem was very simple. you are setting item to the item_row data each time through the loop. Instead you have to concatenate to the end of the string this is simple php stuff |
Welcome Guest, Not a member yet? Register Sign In |