可以使用php codeigniter在同一模型中的另一个函数中使用一个函数中的变量

时间:2011-05-26 06:02:33

标签: php codeigniter

这是我的代码......以及我对代码的怀疑 请参阅函数toltalRetailerComm($userId) ...我正在获取

的值
  

$ shoppeId

  

$ STOREID

通过以这种方式使用函数retailerDailyComm($userId, $fromDate, $toDate)

,可以在下一个函数retailerDailyComm($shoppeId,$storeId, $fromDate, $toDate)中使用此相同的变量
function toltalRetailerComm($userId) {

    $sql = "SELECT shoppe_id FROM atm_super_shoppe WHERE user_id='$userId'";
    $shoppe_query = $this->db->query($sql);

    $sql = "SELECT shoppe_id FROM atm_store WHERE user_id='$userId'";
    $store_query = $this->db->query($sql);

    if ($shoppe_query->num_rows() > 0) {
        $result = $shoppe_query->row();
        $shoppeId = $result->shoppe_id;

        $sql = "SELECT COALESCE(sum(commission),0) as commission FROM atm_shoppe_commission WHERE shoppe_id ='$shoppeId'";
        //$sql = "SELECT commission FROM atm_shoppe_commission WHERE shoppe_id='$shoppeId ' BETWEEN '03-5-2011' AND '05-5-2011'";
        $query = $this->db->query($sql);
        print_r($shoppeId);

        if ($query->num_rows > 0) {
            $result = $query->row();
            $commission = $result->commission;
            return $commission;
        }

    } else
        if ($store_query->num_rows() > 0) {
            $result = $store_query->row();
            $storeId = $result->shoppe_id;

            $sql = "SELECT COALESCE(sum(commission),0) as commission FROM atm_store_commission WHERE shoppe_id ='$storeId'";
            //$sql = "SELECT commission FROM atm_store_commission WHERE shoppe_id='$storeId ' BETWEEN '03-5-2011' AND '05-5-2011'";
            $query = $this->db->query($sql);
            print_r($storeId);
            if ($query->num_rows > 0) {
                $result = $query->row();
                $commission = $result->commission;
                return $commission;
            }
        }
}

/ * ** * ** * *** TOTAL RETAILER COMMISSION ENDS < / EM> * ** * ** * ** * ** * ** * ** * ** * ** * **** /

/ * ** * ** * *** 总零售商开始结束DATE COMMISSION STARTS * ** * ** * ** * ** * **** /

function retailerDailyComm($userId, $fromDate, $toDate) {

    $sql = "SELECT shoppe_id FROM atm_super_shoppe WHERE user_id='$userId'";
    $shoppe_query = $this->db->query($sql);

    $sql = "SELECT shoppe_id FROM atm_store WHERE user_id='$userId'";
    $store_query = $this->db->query($sql);

    if ($shoppe_query->num_rows() > 0) {
        $result = $shoppe_query->row();
        $shoppeId = $result->shoppe_id;

        $sql = "SELECT commission as retailDailyCommission FROM atm_shoppe_commission WHERE shoppe_id='$shoppeId ' BETWEEN '$fromDate' AND '$toDate'";
        $query = $this->db->query($sql);
        if ($query->num_rows > 0) {
            $result = $query->row();
            $retailDailyCommission = $result->retailDailyCommission;
            return $retailDailyCommission;

        } else
            if ($store_query->num_rows() > 0) {
                $result = $store_query->row();
                $storeId = $result->shoppe_id;

                $sql = "SELECT commission as retailDailyCommission FROM atm_store_commission WHERE shoppe_id='$storeId' BETWEEN '$fromDate' AND '$toDate'";
                $query = $this->db->query($sql);
                if ($query->num_rows > 0) {
                    $result = $query->row();
                    $retailDailyCommission = $result->retailDailyCommission;
                    return $retailDailyCommission;
                }
            }
    }
}

1 个答案:

答案 0 :(得分:0)

你在课堂上,改变你的变量,它应该有用。

$this->shoppeId
$this->storeId