douxian8883 2016-01-19 04:56
浏览 31
已采纳

在插入数据库之前在数组上添加其他值

I wanted to add a header to my array before inserting it to my database. its for my auto-generate username function wherein usernames will go by the account type and followed by their account id

e.g account type = student account id = 20-1491-1243 so the username would be: STUD20-1391-1243

these are my codes that i used for my model:

     `***function add_student($data){

        $insert = array(
                'idno'          =>$data['idno'],
               'f_name'         =>$data['f_name'],
                'm_name'            =>$data['m_name'],
                'l_name'    =>$data['l_name'],
                'birth'    =>$data['birth'],
                'contact_number'    =>$data['contact_number'],
                'email'     =>$data['email'],
                'year'    =>$data['year'],
                'strand'    =>$data['strand'],
                'usertype'  =>'student',
                'username'          => ['STUD']$data['idno'],
                'password'      =>'123456'                    
                );
                $this->db->insert('user',$insert);    
        }***`

everything else works, i just cant seem to add the STUD in the beginning of my usernames. right now thats an error because i included ['STUD'] before $data. I am at a complete loss.

  • 写回答

1条回答 默认 最新

  • doupinyan0186 2016-01-19 05:07
    关注

    You are missing contactenation.

    Change this line

      'username'          => ['STUD']$data['idno'],
    

    To this

      'username'          => "STUD".$data['idno'],
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?