gpt4 book ai didi

php - 如何以数组形式检索包含括号 {} 之间的数据的 MySQL 数据库字段

转载 作者:行者123 更新时间:2023-11-29 07:20:29 26 4
gpt4 key购买 nike

我需要从 magento sales_flat_quote_ payment 中的此表中检索数据。表中有一个名为 additional_data 的字段。

additional_data字段中是括号内的数据{ }

additional data

这是数据的格式

a:6:{
s:14:"component_mode";
s:4:"ebay";
s:14:"payment_method";
s:6:"PayPal";
s:16:"channel_order_id";
s:9:"123654789";
s:17:"channel_final_fee";
d:5.3600000000000003;
s:12:"transactions";
a:1:{
i:0;
a:4:{
s:14:"transaction_id";
s:15:"987456321456987";
s:3:"sum";
d:66.989999999999995;
s:3:"fee";
d:1.5700000000000001;
s:16:"transaction_date";
s:19:"2016-03-31 02:54:18";
}
}
s:6:"tax_id";
s:0:"";
}

如何像数组一样访问这些数据?

我特别需要从此数据中提取 d:1.5700000000000001;s:3:"fee"; 值。

我尝试了$additional_data->transactions->fee但没有成功。

这是我使用的代码。

$con = mysql_connect("localhost","user","password");

if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("database", $con);

$po = $_GET['po'];


if( ! is_numeric($po) )
die('invalid PO#');

$query1 = "SELECT * FROM `sales_flat_quote` WHERE `reserved_order_id` LIKE '" . $po . "' LIMIT 0 , 30";

$get_entity_id = mysql_query($query1);

while($row = mysql_fetch_array($get_entity_id, MYSQL_ASSOC))
{
$entity_id = $row['entity_id'];

echo " <div style='margin:30px 0px;'>
entity_id: $entity_id<br />
</div>
";
}

$query2 = "SELECT * FROM `sales_flat_quote_payment` WHERE `quote_id` = " . $entity_id . " LIMIT 0 , 30";

$get_additional_data = mysql_query($query2);

while($row = mysql_fetch_array($get_additional_data, MYSQL_ASSOC))
{
$additional_data = $row['additional_data'];

echo " <div style='margin:30px 0px;'>
additional_data: $additional_data<br />
</div>
";
}

echo " <div style='margin:30px 0px;'>
fee: $additional_data->transactions->fee<br />
</div>
";

mysql_close($con);

更新:我取消了数组的序列化。现在看起来像这样。

array(6) {

["component_mode"]=> string(4) "ebay"
["payment_method"]=> string(6) "PayPal"
["channel_order_id"]=> string(9) "123654789"
["channel_final_fee"]=> float(3.6)
["transactions"]=> array(1) {
[0]=> array(4) {
["transaction_id"]=> string(15) "987456321456987"
["sum"]=> float(45)
["fee"]=> float(1.16)
["transaction_date"]=> string(19) "2016-03-31 05:43:43"
}
}
["tax_id"]=> string(0) ""
}

我仍然无法从此数组中检索我想要的数据。

我想检索$additional_data->transactions->fee

我该怎么做?

最佳答案

它看起来像一个序列化数组。请参阅unserialize() php doc

可以通过以下方式检索费用:$additional_data['transactions'][0]["fee"]

关于php - 如何以数组形式检索包含括号 {} 之间的数据的 MySQL 数据库字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36326986/

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