Forum Moderators: coopster

Message Too Old, No Replies

Output says "Array" instead of array contents...

ourput says "Array" instead of array contents.

         

vacorama

8:35 pm on May 16, 2005 (gmt 0)

10+ Year Member



im havin a little trouble over here and was wondering if anyone can tell what's wrong with this.. i have this script that sorts my products based on a short quiz people will in.. In the end it displays the contents of the array "$_machine"... then i email the results to myself as well, but for some reason i just can't get the the contents of $_machine into the email body, it's keeps popping up as "Array"... here is the code.. my guess is im missing something really stupid.. the array displays fine when the program is run, and the other arrays go through to the email, but not $_machine, can anyone help me out?

#prints $_machine array into a multi color table
$row_color = array ('ffcc99', 'FFffff');
$color_index = 0;
print "<table>\n";

foreach ($_machine as $key => $value)
{
print '<tr bgcolor="' . $row_color[$color_index] . '">';
print "<td><span class=\"style1\">$key</span></td> <td> $value </td></tr>\n";
#swtich color
$color_index = 1 - $color_index;
}
print '</table>';

###ends large table
print '</tr></table></div></td></span>';

#####mail results to myself###################

$mail_body= " $email has just looked over test from $_SERVER[REMOTE_ADDR] with the following the results $_machine ";
mail('my@email.com','Product Test', $mail_body);

dreamcatcher

8:45 pm on May 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

Yes your $_machine variable is an array, this is why you get 'Array':

The code works before because you are correctly using a foreach loop. A foreach loop is used to loop through an array. In this case the array is $_machine. You need to assign the results to a string. So where you have the print command add a second line assigning the same data to a string, then when you have finished send this to your e-mail.

Hope that helps.

dc

StupidScript

8:47 pm on May 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How are you generating $mail_body? Perhaps you could populate it at the same time as you are printing the array's contents?

foreach ($_machine as $key => $value) 

{ 

print '<tr bgcolor="' . $row_color[$color_index] . '">'; 

print "<td><span class=\"style1\">$key</span></td> <td> $value </td></tr>\n"; 

#switch color 

$color_index = 1 - $color_index; 

[b]$mail_body .= $key.": ".$value."\n";[/b]

} 

Or something like that?

mcibor

9:18 pm on May 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think that you just forgot, that mail isn't html. Moreover variable $_machine is not a string, as you would wish. You should create you mail_body at the same time you create html:

$mail_body = " $email has just looked over test from $_SERVER[REMOTE_ADDR] with the following the results:\n\n";
#your beginning...
foreach ($_machine as $key => $value){
print '<tr bgcolor="' . $row_color[$color_index] . '">';
print "<td><span class=\"style1\">$key</span></td> <td> $value </td></tr>\n";
$mail_body .= "$key: $value\n";

#switch color
$color_index = 1 - $color_index;
}
print '</table>';

###ends large table
print '</tr></table></div></td></span>';

#####mail results to myself###################
mail('my@email.com','Product Test', $mail_body);


This should do
Michal Cibor

vacorama

12:43 am on May 17, 2005 (gmt 0)

10+ Year Member



ahhhh... that's perfect, worked like a charm! thank you guys so much.