gpt4 book ai didi

php - 分解数组以生成两个变量,以便我可以从数据库表中获取信息以发送电子邮件

转载 作者:行者123 更新时间:2023-12-01 00:53:35 24 4
gpt4 key购买 nike

是的,所以我在数据库的一个表中有一个数组。我需要将这个数组分开,这样我就可以使用它的一部分从我的数据库中的另一个表中获取信息,然后发送一封包含该信息的电子邮件。

我在表中的数组是这样的

30-1,

30是产品ID,1是数量。 (购买的商品数量)

我是不是做错了这个布偶?

//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];

我认为这会给我两个变量。$product_id 为 30,$product_quantity 为 1

然后我尝试使用此信息从另一个表中获取更多信息。

$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'];
}

如您所见,我的 WHERE 正在查看 $product_id 变量。因此,当我尝试发送电子邮件时,我收到了电子邮件,但看不到 $product_name$product_price。请忽略那些其他变量,它们在电子邮件中显示正常并且来自不同的查询。

/////// 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);

我的是 explode() 吗?或者是别的什么?

这绝对是在扼杀我的大脑,我已经研究了几个小时了。请帮忙! :)

最佳答案

试试 $prod_quant_array = explode("-", $prod_quant_array);

作为旁注,您应该通过添加数量字段并让当前字段仅包含产品 ID 来真正规范您的数据库。这样您还可以在同一个查询中加入产品价格,而不是发送另一个查询。

关于php - 分解数组以生成两个变量,以便我可以从数据库表中获取信息以发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13161343/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com