简体   繁体   English

我正在似乎是一个无限循环,不知道为什么-PHP / WordPress

[英]I'm getting what seems to be an infinite loop and can't figure out why - PHP/WordPress

I'm running through some distinct user ID's (about 147 of them, retrieved from a table with many duplicates) with a foreach loop and then when retrieved, using them to retrieve more user details. 我正在使用foreach循环遍历一些不同的用户ID(大约147个,从具有许多重复项的表中检索),然后在检索时使用它们来检索更多用户详细信息。 I then place these details within an array in order to push them to my JavaScript. 然后,我将这些详细信息放在一个数组中,以将其推送到我的JavaScript中。

For some reason the result that I get from the array is what seems to be an infinite loop that has quit somewhere in the process. 由于某种原因,我从数组中得到的结果似乎是一个无限循环,该循环已在过程中的某个位置退出。

Here's an example: 这是一个例子:

在此处输入图片说明

This is the code that I am currently running: 这是我当前正在运行的代码:

public function payments_rt_search() {
    global $wpdb;

    $date1 = $_POST['date1'];
    $date2 = $_POST['date2'];
    $threshold = intval($_POST['threshold']);

    $results = $wpdb->get_results( "SELECT DISTINCT vendor_id FROM {$wpdb->prefix}wcpv_commissions WHERE order_date BETWEEN '".$date1."'  AND '".$date2."'");

    $past_threshold_users = [];
    // echo json_encode($results);
    // wp_die();
    foreach ($results as $user_R) {
        $total_commissions = $wpdb->get_results( "SELECT SUM(product_commission_amount) AS TotalCommissions FROM {$wpdb->prefix}wcpv_commissions WHERE vendor_id = ".$user_R->vendor_id);
        $total_commission = 0;
        foreach($total_commissions as $total_commission_res)
        {
            $total_commission = $total_commission_res->TotalCommissions;
        }
        if ($total_commission >= $threshold)
        {
            $res2 = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wcpv_commissions WHERE vendor_id = ".$user_R->vendor_id." LIMIT 1");
            // echo json_encode($res2[0]);
            // wp_die();
            //Add user details to array
            $user_deets = $res2[0];
            $user_arr = array(
                'vendor_id' => $user_deets->vendor_id,
                'vendor_name' => $user_deets->vendor_name,
                'paypal_email' => '',
                'amount' => $total_commission,
                'currency' => '$',
                'commission_status' => $user_deets->commission_status
            );
            $past_threshold_users[] = $user_arr;
            // echo json_encode($user_arr);
            // wp_die();                
        }
        else
        {
            continue;
        }
        echo json_encode($past_threshold_users);
    }

    //echo json_encode($results);

    wp_die();
}

Try this code 试试这个代码

I have move this echo json_encode($past_threshold_users); 我已经移动了这个echo json_encode($past_threshold_users); code after foreach loop. foreach循环后的代码。

    public function payments_rt_search() {
        global $wpdb;

        $date1 = $_POST['date1'];
        $date2 = $_POST['date2'];
        $threshold = intval($_POST['threshold']);

        $results = $wpdb->get_results( "SELECT DISTINCT vendor_id FROM {$wpdb->prefix}wcpv_commissions WHERE order_date BETWEEN '".$date1."'  AND '".$date2."'");

        $past_threshold_users = [];
        // echo json_encode($results);
        // wp_die();
        foreach ($results as $user_R) {
            $total_commissions = $wpdb->get_results( "SELECT SUM(product_commission_amount) AS TotalCommissions FROM {$wpdb->prefix}wcpv_commissions WHERE vendor_id = ".$user_R->vendor_id);
            $total_commission = 0;
            foreach($total_commissions as $total_commission_res)
            {
                $total_commission = $total_commission_res->TotalCommissions;
            }
            if ($total_commission >= $threshold)
            {
                $res2 = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wcpv_commissions WHERE vendor_id = ".$user_R->vendor_id." LIMIT 1");
                // echo json_encode($res2[0]);
                // wp_die();
                //Add user details to array
                $user_deets = $res2[0];
                $user_arr = array(
                    'vendor_id' => $user_deets->vendor_id,
                    'vendor_name' => $user_deets->vendor_name,
                    'paypal_email' => '',
                    'amount' => $total_commission,
                    'currency' => '$',
                    'commission_status' => $user_deets->commission_status
                );
                $past_threshold_users[] = $user_arr;
                // echo json_encode($user_arr);
                // wp_die();                
            }
            /*else
            {
                continue;
            }   */     
        }

        echo json_encode($past_threshold_users);
        //echo json_encode($results);

        wp_die();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法弄清楚为什么我的PHP代码出现服务器错误 - Can't figure out why I'm getting Server errors from my PHP code 无法找出我在用这个php条件做错了什么 - Can't figure out what I'm doing wrong with this php conditional 我正在尝试 cURL 这个简单的 URL 在 PHP 中,我不知道我做错了什么 - I'm trying to cURL this simple URL in PHP and I can't figure out what I'm doing wrong 在我的实时应用程序上出现行为,这很像会话冲突。 不知道为什么 - Getting behavior on my live app that seems a lot like session collisions. Can't figure out why 无法弄清楚为什么我不断收到Mysql错误 - Can't figure out why I keep getting a Mysql error 挣扎于PHP,无法弄清楚我做错了什么 - Struggling with PHP, can't figure out what I did wrong 我无法弄清楚为什么其中一个PHP脚本无法正常工作 - I can't figure out why one of these PHP scripts is not working mysqli 的插入查询似乎不起作用,我不知道为什么 - Insert query for mysqli seems to not be working and I can't figure out why 我不知道php语法 - I can't figure out php syntax 我正在尝试对PHP数组进行排序,但无法弄清楚如何 - I'm trying to sort a PHP Array, but can't figure out how
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM