Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么在数据库中保存数据时使用NULL_Php_Sql Server 2008_Codeigniter 3 - Fatal编程技术网

Php 为什么在数据库中保存数据时使用NULL

Php 为什么在数据库中保存数据时使用NULL,php,sql-server-2008,codeigniter-3,Php,Sql Server 2008,Codeigniter 3,我正在尝试使用foreach 这是我从表格中得到的信息 Array ( [mulai] => 2016-08-28 [akhir] => 2016-08-31 [keterangan] => remarks [nip] => Array ( [0] => 1004384 [1] => 1602744 [2] => 1501039

我正在尝试使用
foreach

这是我从表格中得到的信息

  Array
(
    [mulai] => 2016-08-28
    [akhir] => 2016-08-31
    [keterangan] => remarks
    [nip] => Array
        (
            [0] => 1004384
            [1] => 1602744
            [2] => 1501039
        )

)
然后是我的保存查询

$jumlahrange = $this->db->query("SELECT DATEDIFF(day,'".$mulai."','".$akhir."') AS diff")->row();
        $totaldata = count($nip);
        $skrg = $this->db->query("SELECT GETDATE() tgl")->row();
            for($x = 0;$x<=$totaldata;$x++)
                {
                    for($y=0;$y<$jumlahrange->diff;$y++){
                        $this->db->query("INSERT INTO attendance 
                            (Nip,AttendanceDate,InTime,OutTime,AttendanceCode,RosterCode,LocationCode,Remarks,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy)
                        values(
                            '".$nip[$x]."',DATEADD(DAY,".$y.",'".$mulai."'),'','','P3','','','".$keterangan."','".$skrg->tgl."','$niplogin','','')
                        ");
                    }
            }
$jumlahrange=$this->db->query(“选择DATEDIFF(day,“$mulai.”,“$akhir.”)作为diff”)->row();
$totaldata=计数($nip);
$skrg=$this->db->query(“选择GETDATE()tgl”)->row();
对于($x=0;$xdb->查询(“插入到考勤中
(Nip、AttendanceDate、InTime、OutTime、AttendanceCode、RosterCode、LocationCode、备注、CreatedDate、CreatedBy、ModifiedDate、ModifiedBy)
价值观(
“$nip[$x]。”,DATEADD(DAY),“$y.”,“$mulai.”,“,”,“P3”,“,”,“,”,“$keterangan.”,“,”,“$skrg->tgl.”,“$niplogin”,“,”,“,”)
");
}
}
我的
save
没有问题,但是我的表中有这样的空字段。在
10,11,12行中。该行不应该存在,对吗

我使用SQLServer2008和Codeigniter。我知道我可以使用
insert_uBatch
,但我想使用这种方式


在($x=0;$x的
行中,这一行就在您的指尖。$nip[$x]为空。在第一个循环$nip[$x]上记录错误或转储并终止,然后查看它返回什么。如果它实际上不是空的,则可能是数据类型问题(字符串与int)。

要解决此类问题,您可以改用foreach循环

    foreach($resourcedata as $value){
          //your code goes here and you will get all array elements sequentially in **$value** variable
    }

尝试使用foreach循环而不是for和check