获取CI模型中单个结果数组的值



i在我的模型上有这个功能。

function agent_claim($agentcode,$bankname, $accowner, $accnumber){
    $result= $this->db->query("INSERT INTO account (bank, number,name) VALUES ('$bankname', '$accnumber', '$accowner');");
    $accid= $this->db->query("SELECT LAST_INSERT_ID();")->result();
    $result = $this->agent_account($agentcode, $accid);
    return result;
}

此查询的返回值必须是单个值。

$accid= $this->db->query("SELECT LAST_INSERT_ID();")->result();

我不能插入这个语法

$result = $this->agent_account($agentcode, $accid);

因为返回值不是一个数字而是一个数组。如何获取$accid的值

您应该像下面这样使用活动记录。关于Active Records的参考

function agent_claim($agentcode,$bankname, $accowner, $accnumber){
        $data = array(
         'bank' => $bankname,
         'number' => $accnumber ,
         'name' => $accowner
        );
    //insert data to acccount table
        $this->db->insert('account', $data); 
    //get your last insert id
        $accid=  $this->db->insert_id();
        $result = $this->agent_account($agentcode, $accid); //this call your other function in model
        return $result;
    }

最新更新