Php 获取CSV中的重新标记行

Php 获取CSV中的重新标记行,php,csv,Php,Csv,我这里有一个脚本,它将获取csv中的所有行,并将它们插入数据库(确切地说是FileMaker),我希望它计数到100行,打破循环,然后告诉我剩下的重新制作行。我的代码如下,请参阅,任何帮助都将不胜感激 public function insertTimesheet() { //Get the public variables $fm = $this->fm; $timesheet = $this->data['timesheets']; $tot

我这里有一个脚本,它将获取csv中的所有行,并将它们插入数据库(确切地说是FileMaker),我希望它计数到100行,打破循环,然后告诉我剩下的重新制作行。我的代码如下,请参阅,任何帮助都将不胜感激

 public function insertTimesheet() {


    //Get the public variables
    $fm = $this->fm;
    $timesheet = $this->data['timesheets'];
    $total = count($timesheet);
    $fm = $this->fm;

    $count = 0;
    $total = count($timesheet);

    //Loop through the data items in the array
    foreach ($timesheet as $element) {

        //Checks each key value in the array
        for ($i = 0; $i < count($timesheet); ++$i) {

            if($i == 100){
                printf('%d Timesheets added', $i);
                break;

                // Return which timesheets have not been added //
            }

            //Prevents duplicate entries
            $count++;
            //Manually add some data to the array
            $timesheet[$i]['Created_By_Staff_ID']   = $_SESSION["user"]->staff_id;
            $timesheet[$i]['Key_Staff_ID']          = $_SESSION["user"]->staff_id;
            $timesheet[$i]['Timesheet_Type']        = 'CSV_UPLOAD';
            $timesheet[$i]['Resource_ID']           = 'N/A At this time [CSV UPLOAD]';

            //Convert the dates to USA dates (FileMaker Format)
            $timesheet[$i]['Date_From']             = $this->convertDate($timesheet[$i]['Date_From']);
            $timesheet[$i]['Date_To']               = $this->convertDate($timesheet[$i]['Date_To']);

            //Insert the data into the Database
            $addReq = & $fm->createRecord('Web_Staff_Timesheet', $timesheet[$i]);
            $result = $addReq->commit();

            //Checks for filemaker errors
            if (!FileMaker::isError($result)) {
                $return['error'] = false;
                $return['msg'] = 'Timesheet added successfully';
                $strOut = sprintf('<br />Working on %d of %d timesheets', $count, $total);
                //return true;
            } else {
                $return['error'] = true;
                $return['errorCode'] = $result->code;
                $return['msg'] = 'Unable to add Timesheet';
                $strOut = sprintf('<br />Sorry, we could not add your time sheet, FileMaker Produced this error: %s <br /> Failed to insert the following timesheets [Line number]: ', $return['errorCode'], $count);
                return false;
            }
        }
        break;
    }

    //Clear the array to prevent duplicates
    unset($timesheet, $element, $this->data);
    return $strOut;
}
公共函数插入时间表(){
//获取公共变量
$fm=$this->fm;
$timesheet=$this->data['timesheets'];
$total=计数($timesheet);
$fm=$this->fm;
$count=0;
$total=计数($timesheet);
//循环遍历数组中的数据项
foreach($element形式的时间表){
//检查数组中的每个键值
对于($i=0;$i<计数($timesheet);+$i){
如果($i==100){
printf(“%d个添加的时间表,$i);
打破
//返回尚未添加的时间表//
}
//防止重复条目
$count++;
//手动向数组中添加一些数据
$timesheet[$i]['Created\u By\u Staff\u ID']=$\u SESSION[“user”]->Staff\u ID;
$timesheet[$i]['Key\u Staff\u ID']=$\u SESSION[“user”]->Staff\u ID;
$timesheet[$i]['timesheet\u Type']='CSV\u UPLOAD';
$timesheet[$i]['Resource_ID']=“此时不适用[CSV上载]”;
//将日期转换为美国日期(FileMaker格式)
$timesheet[$i]['Date\u From']=$this->convertDate($timesheet[$i]['Date\u From']);
$timesheet[$i]['Date\u To']=$this->convertDate($timesheet[$i]['Date\u To']);
//将数据插入数据库
$addReq=&$fm->createRecord('Web_Staff_时间表',$Timesheet[$i]);
$result=$addReq->commit();
//检查文件生成器错误
如果(!FileMaker::isError($result)){
$return['error']=false;
$return['msg']='Timesheet added successfully';
$strOut=sprintf(“
处理%d张时间表中的%d张,$count,$total); //返回true; }否则{ $return['error']=true; $return['errorCode']=$result->code; $return['msg']='无法添加时间表'; $strOut=sprintf('
抱歉,我们无法添加您的时间表,FileMaker产生了此错误:%s
未能插入以下时间表[行号]:',$return['errorCode'],$count); 返回false; } } 打破 } //清除阵列以防止重复 取消设置($timesheet,$element,$this->data); 返回$strOut; }
仅供各位参考,我现在已经整理好了。无论如何,谢谢你抽出时间

打印计数($timesheet)-100不是为你做的吗?不,对不起,我想要这些行中的数据,而不仅仅是行数。对不起,如果我不清楚这一点。您能在$timesheet数组中显示示例数据吗