mysql – join 2 wordpress plugin command tables


I have two table wp_wcfm_marketplace_orders
wp_wcfm_affiliate_orders

I need data call where wp_wcfm_affiliate_orders.orderid wp_wcfm_marketplace_orders.order_id

enter the description of the image here

it calls code table wp_wcfm_affiliate_orders

class WCFMaf_Affiliate_Stats_Controller {

public function __construct() {
    global $WCFM;

    $this->processing();
}

public function processing() {
    global $WCFM, $wpdb, $_POST, $WCFMu, $WCFMaf;

    $length = $_POST('length');
    $offset = $_POST('start');

    $affiliate_id = $_POST('wcfm_affiliate'); 
    $status          = $_POST('status_type');

    $sql  = "SELECT COUNT(ID) FROM `{$wpdb->prefix}wcfm_affiliate_orders`";
    $sql .= " WHERE 1=1";
    $sql .= " AND {$wpdb->prefix}wcfm_affiliate_orders.affiliate_id = {$affiliate_id}";
    if( $status ) $sql .= " AND {$wpdb->prefix}wcfm_affiliate_orders.commission_status = '{$status}'";
    $sql .= ' AND `is_trashed` = 0';
    $affiliate_count = $wpdb->get_var( $sql );

    // Get Product Count
    $sql  = "SELECT  * FROM  {$wpdb->prefix}wcfm_affiliate_orders  ";
    $sql .= " WHERE 1=1";
    $sql .= " AND {$wpdb->prefix}wcfm_affiliate_orders.affiliate_id = {$affiliate_id} 

    ";
    if( $status ) $sql .= " AND {$wpdb->prefix}wcfm_affiliate_orders.commission_status = '{$status}'";
    $sql .= ' AND `is_trashed` = 0';
    $sql .= " ORDER BY `ID` DESC";
    $sql .= " LIMIT {$length}";
    $sql .= " OFFSET {$offset}";


    $wcfm_affiliate_orders_array = $wpdb->get_results( $sql );
    $wcfm_affiliate_order_count  = count( $wcfm_affiliate_orders_array );

    // Generate Products JSON
    $wcfm_affiliate_json = '';
    $wcfm_affiliate_json = '{
                                                        "draw": ' . $_POST('draw') . ',
                                                        "recordsTotal": ' . $wcfm_affiliate_order_count . ',
                                                        "recordsFiltered": ' . $affiliate_count . ',
                                                        "data": ';
    $index = 0;
    $wcfm_affiliate_orders_json_arr = array();

    if(!empty($wcfm_affiliate_orders_array)) {
        foreach( $wcfm_affiliate_orders_array as $wcfm_affiliate_order_single ) {


            // Status
            if( $wcfm_affiliate_order_single->commission_status == 'pending' ) {
                $wcfm_affiliate_orders_json_arr($index)() = '';
            } else {
                $wcfm_affiliate_orders_json_arr($index)() = '';
            }
            sprintf($statu2  );
            // Commission
            $wcfm_affiliate_orders_json_arr($index)() = '#' . sprintf( '%06u', $wcfm_affiliate_order_single->ID ) . ''.

             sprintf(  $wcfm_affiliate_orders->order_id )    
                ;

            // Amount
            $wcfm_affiliate_orders_json_arr($index)() = wc_price( $wcfm_affiliate_order_single->commission_amount ) ; 



            // Type
            if( $wcfm_affiliate_order_single->commission_type == 'vendor' ) {
                $wcfm_affiliate_orders_json_arr($index)() = '' . __( 'Vendor Register', 'wc-frontend-manager-affiliate' ) . '';

            } else if( $wcfm_affiliate_order_single->commission_type == 'vendor_order' ) {
                $wcfm_affiliate_orders_json_arr($index)() = '' . __( 'Vendor Order', 'wc-frontend-manager-affiliate' ) . '';
            } else {
                $wcfm_affiliate_orders_json_arr($index)() = '' . __( 'Order', 'wc-frontend-manager-affiliate' ) . ''.
                sprintf(  $wcfm_affiliate_order_single->order_id )    
                ;

                        // Commission

            }

            // Date
            $wcfm_affiliate_orders_json_arr($index)() =  date_i18n( wc_date_format() . ' ' . wc_time_format(), strtotime($wcfm_affiliate_order_single->created) );

            // Action
            $actions = '–';
            if( $wcfm_affiliate_order_single->commission_status == 'pending' ) {
                if( !wcfm_is_affiliate() ) {
                    $actions = '';
                }
            } elseif( $wcfm_affiliate_order_single->commission_paid_date ) {
                $actions = ' ' . date_i18n( wc_date_format() . ' ' . wc_time_format(), strtotime( $wcfm_affiliate_order_single->commission_paid_date ) );
            }
            $wcfm_affiliate_orders_json_arr($index)() = apply_filters ( 'wcfm_affiliate_stats_actions', $actions, $wcfm_affiliate_order_single );

            $index++;
        }                                               
    }
    if( !empty($wcfm_affiliate_orders_json_arr) ) $wcfm_affiliate_json .= json_encode($wcfm_affiliate_orders_json_arr);
    else $wcfm_affiliate_json .= '()';
    $wcfm_affiliate_json .= '
                                                }';

    echo $wcfm_affiliate_json;
}

}