duaevb1511 2010-11-29 04:49
浏览 66
已采纳

PHP - 添加多个数据库条目

I have a function that adds an entry to the database, the code i have at the moment is as follows:

    function create_internal_role($rolename, $rolekey)
{
    $data = array(
        'name'  => $rolename,
        'key'   => $rolekey.'1'
    );
    if (!is_null($res = $this->ci->internal_roles->create_role($data))) {
        return $data;
    }

    return NULL;
}

What i want to do, is using the same function add another 2 data arrays with a 2 and 3 behind the $rolekey, so that with the one function, it adds 3 lots of data, rolekey1, rolekey2 and rolekey3

How would i go about doing that?

  • 写回答

2条回答 默认 最新

  • dongtong848825 2010-11-29 04:55
    关注

    With out knowing about your structure and from the current phrasing of your question, the obvious answer would seem to be this:

    function create_internal_role($rolename, $rolekey)
    {
        $ret = array();
        $data = array(
            'name'  => $rolename,
            'key'   => $rolekey.'1'
        );
        if (!is_null($res = $this->ci->internal_roles->create_role($data))) {
            $ret[] = $data;
        }
    $data = array(
                'name'  => $rolename,
                'key'   => $rolekey.'2'
            );
            if (!is_null($res = $this->ci->internal_roles->create_role($data))) {
                $ret[] = $data;
            }
    $data = array(
                'name'  => $rolename,
                'key'   => $rolekey.'3'
            );
            if (!is_null($res = $this->ci->internal_roles->create_role($data))) {
                $ret[] = $data;
            }
    
            return $ret;
        }
    

    If you give more detail in your question, I may be able to give you a better answer.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用