I am currently developing a shopping cart in php for my company using a SQL database. I want to make it so when the buyer hits the send button, their order info will be sent to us via email. The mail function is pretty simple, but it forces you to stick your message into a variable. I can get the shipping & billing info into the message variable without a problem, but once it comes to the part of adding in the items, their item number, description, cost, and quanity, I cannot figure out how to add that data to the end of the message variable. Currently, I am using a foreach command to cycle through the cart. Heres the code I use for that:
function get_product_info($itemnumber)
{
$query = "select * from products where itemnumber='$itemnumber'";
$result = @($query);
if (!$result) return false;
$temp = @mysql_fetch_array($result);
return $temp;
}
foreach ($cart as $itemnumber => $qty)
{
$temp = get_product_info($itemnumber);
echo $temp["itemnumber"]." :: ".$temp["description"]." :: ".$temp["price"]." :: ".$qty"\n";
};
That code is not in the right order, but it shows you how I am pulling up the info. The $cart array only contains the item number and the quanity, the rest is pulled from the SQL database using that data. The solution I am thinking of involves the foreach statement making 1 long string with the appropriate adjustments for screen presentation. Any ideas or am I going about it the wrong way?