Right, so I have an array in one table in my database. I need to break this array apart so I can use one bit of it to get information from another table in my database and then send an email with that information in.
My array in the table looks like this
30-1,
30 is the product ID and 1 is the quantity. (Quantity of item purchased)
Have I been a muppet and got this wrong?
//Get product_id_array of item purchased
$sql = mysql_query("SELECT product_id_array FROM transactions WHERE id='$orderID'")or die(mysql_error());
while($row = mysql_fetch_array($sql)){
$prod_quant_array = $row['product_id_array'];
}
//Explode prod_quant_array
(explode("-", $prod_quant_array));
$product_id = $prod_quant_array[0];
$product_quantity = $prod_quant_array[1];
I thought that this would then give me two variables.
$product_id would be 30 and $product_quantity would 1
I’m then trying to use this information to get more information from another table.
$sql = mysql_query("SELECT product_name, product_price FROM products WHERE id='$product_id'")or die(mysql_error());
while($row = mysql_fetch_array($sql)){
$product_name = $row['product_name'];
$product_price = $row['product_price'];
}
As you can see, my WHERE is looking at the $product_id variable.
So when I try and send the email, I get the email, but I can’t see the $product_name or $product_price. Please ignore those other variables, they are displaying fine in the email and are coming from a different query.
/////// Send Email ///////
$to = "" . $payer_email . "";
$subject = "Confirmation of your order";
$message .= "Dear " . $first_name . " " . $last_name . ",
This is an email to confirm your recent purchase of goods with Bloodlust.
You have ordered:
--------------------------------------------------
" . $product_name . ".
" . $product_price . "
--------------------------------------------------
Please keep this email for your records.
Please note that this is not a proof of transaction.
Thank you.";
$from = "no-reply@blood-lust.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
Is my explode() ?
Or is it something else?
This is absolutely killing my brain, I’ve been at it for hours. Please help! 🙂
Try
$prod_quant_array = explode("-", $prod_quant_array);And as a side note you should really normalize your database by adding a quantity field and have the current field only hold the product id. That way you can also join the product price in the same query, rather than sending another one.