gpt4 book ai didi

php - Foreach 不显示结果

转载 作者:行者123 更新时间:2023-11-30 00:10:01 26 4
gpt4 key购买 nike

您好,我正在使用以下查询,需要从此查询中获取 order_idproduct_id ,当我在 phpmyadmin 中运行查询时,结果会显示出来。

global $wpdb;

$sql = "SELECT oi.order_id, p.ID as product_id, p.post_title, p.post_author as seller_id,
oim2.meta_value as order_total, terms.name as order_status
FROM {$wpdb->prefix}woocommerce_order_items oi
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta oim ON oim.order_item_id = oi.order_item_id
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta oim2 ON oim2.order_item_id = oi.order_item_id
LEFT JOIN $wpdb->posts p ON oim.meta_value = p.ID
LEFT JOIN {$wpdb->term_relationships} rel ON oi.order_id = rel.object_id
LEFT JOIN {$wpdb->term_taxonomy} tax ON rel.term_taxonomy_id = tax.term_taxonomy_id
LEFT JOIN {$wpdb->terms} terms ON tax.term_id = terms.term_id
WHERE
oim.meta_key = '_product_id' AND
oim2.meta_key = '_line_total'
GROUP BY oi.order_id";

$orders = $wpdb->get_results( $sql );

if ( $orders ) {
foreach ($orders as $order) {

$result=customFunction(**$order->order_id,$order->product_id,$order->seller_id**);

}

问题是 $order->order_id$order->product_id 值未传递给函数,而仅传递给 $order->seller_id 正在通过。但在 phpmyadmin 中,所有三个变量的值都存在。

尝试过

echo $orders[product_id] ;
echo $orders[order_id] ;
echo $orders[seller_id];

只有 echo $orders[seller_id]; 显示该值。

这是数组结构:

Array (
[0] => stdClass Object (
[order_id] => 2774
[product_id] => 2531
[post_title] => Klassic Koalas Mug
[seller_id] => 3
[order_total] => 12
[order_status] => cancelled
)
[1] => stdClass Object (
[order_id] => 2869
[product_id] => 2622
[post_title] => Mug, Aqua
[seller_id] => 1
[order_total] => 1
[order_status] => on-hold
)

最佳答案

我会将其放在评论中,但我没有足够的声誉。做:

var_dump($orders)

看看里面有什么。也许它们被作为“oi.order_id”获取。

关于php - Foreach 不显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24150223/

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