gpt4 book ai didi

php - 实现if else循环或else if and can I write function inside a loop的正确方法

转载 作者:行者123 更新时间:2023-12-04 06:25:11 26 4
gpt4 key购买 nike

function toltalRetailerComm($userId) {
//print_r ($shoppeId);
$sql = "SELECT shoppe_id FROM atm_super_shoppe WHERE user_id='$userId'";
$query = $this->db->query($sql);
if ($query->num_rows() > 0) {
$result = $query->row();
$shoppeId = $result->shoppe_id;

$sql = "SELECT COALESCE(sum(commission),0) as commission FROM atm_shoppe_commission WHERE shoppe_id ='$shoppeId'";
$query = $this->db->query($sql);
print_r($shoppeId);
if ($query->num_rows > 0) {
$result = $query->row();
$commission = $result->commission;
return $commission;
} else {

Blockquote block2


            $sql = "SELECT shoppe_id FROM atm_store WHERE user_id='$userId'";
$query = $this->db->query($sql);
if ($query->num_rows() > 0) {
$result = $query->row();
$storeId = $result->shoppe_id;
$sql = "SELECT COALESCE(sum(commission),0) as commission FROM atm_store_commission WHERE shoppe_id ='$storeId'";
$query = $this->db->query($sql);
print_r($storeId);
if ($query->num_rows > 0) {
$result = $query->row();
$commission = $result->commission;
return $commission;
}
}
}
}
}

我是 PHP 新手,谁能告诉我使用 if/else 的正确方法吗?或 elseif在上面显示的代码中?它无法进入第二个街区。另外,我可以在 if/else 中写一个函数吗?堵塞?

最佳答案

你在寻找这样的东西:

function toltalRetailerComm($userId) {
//print_r ($shoppeId);
$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'";
$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'";
$query = $this->db->query($sql);
print_r($storeId);
if ($query->num_rows > 0) {
$result = $query->row();
$commission = $result->commission;
return $commission;
}
}
}

关于php - 实现if else循环或else if and can I write function inside a loop的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6120083/

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