Codeigniter - 从数据库中获取值,然后将其传递给另一个函数

时间:2017-03-15 08:57:37

标签: php codeigniter-3

所以这是我的模型中的获取票证功能:

function get_last_ticket(){

    $WorkBase = $this->session->userdata('cWorkBase');
    $this->db->where('cWorkBase',$WorkBase);
    $query = $this->db->get('tticketno');
    $ticketnow = "";
    foreach($query->result_array() as $row){

        $ticketnow = $row['nTicket'];
    }

    return $ticketnow;
}

然后我试图将其值传递给此函数:

function last_ticket(){
    if($this->session->userdata['cWorkBase'] == 'HO'){
        $TickLoc = 'H';
    }else{
        $TickLoc = 'S';
    }

    $timezone = "Asia/Manila";
    date_default_timezone_set($timezone);

    $year = date('y');
    $LastTicket = $this->get_last_ticket();
    $NextTicketNo = $TickLoc . $year . str_pad($LastTicket,5,'0',STR_PAD_LEFT);

    return $NextTicketNo;
}

last_ticket()函数将数据库中我的计数器中的int从1转换为S1700001,然后将值传递给我的insert函数:

function submit_ticket(){
    $timezone = "Asia/Manila";
    date_default_timezone_set($timezone);
    $latestTicket = $this->last_ticket();

    $data = array(
            'cTicketNo' => var_dump($latestTicket),
            'vDepartment' => $this->session->userdata('vDepartment'),
            'cPCName' => $this->session->userdata('vName'),
            'cUsername' => $this->session->userdata('cUsername'),
            'vCategory' => $this->input->post('vCategory'),
            'vConcern' => $this->input->post('vConcern'),
            'vCaller' => $this->input->post('vCaller'),
            'dDateTimeCalled' => date("Y-m-d H:i:s", time())
            );

    $this->db->insert('tconcerns',$data);


}

这里是数据库表:

表名:tticketno

tticketno table

我没有获得S1700001,而是获得了S1700000,但我的数据库中的数字是1 ..

我做错了什么?非常感谢!

0 个答案:

没有答案