[Ask] Import Excel Into Database Using Php Excel Reader

Hallo guy’s…

i have function code for importing data value from excel into database, i’ll show you :




public function actionImport()

	{

		

		$model=new ATTENDANCE;

		

		if(isset($_POST['ATTENDANCE']))

		{

			Yii::import('ext.excelreader.excel_reader2', true);

			

			$model->attributes=$_POST['ATTENDANCE'];

			

			$import=CUploadedFile::getInstance($model,'filee');

			

			if(isset($import))

			{

				$import->saveAs(Yii::app()->basePath.'/../import/absen.xls');

			}

			

			$data =new Spreadsheet_Excel_Reader('import/absen.xls');

			

			

			$att_emp_id = array();

			$att_emp_name = array();

			$att_date = array();

			$att_clock_in = array();

			$att_clock_out = array();

			

			$success= 0;

			$filed= 0;

			

			for ($j=2; $j <=  $data->sheets[0]['numRows']; $j++)

			{

				$att_emp_id[$j]=$data->sheets[0]['cells'][$j][1];

				$att_emp_name[$j]=$data->sheets[0]['cells'][$j][2];

				$att_date[$j]=$data->sheets[0]['cells'][$j][5];

				$att_clock_in[$j]=$data->sheets[0]['cells'][$j][3];

				$att_clock_out[$j]=$data->sheets[0]['cells'][$j][4];

			}

			

				$baris = $data->rowCount(0);

				

			for($i=2; $i< $baris; $i++)	

			{

				$model=new ATTENDANCE;


					$model->ATT_EMP_ID = $att_emp_id[$i]; 

					$model->ATT_EMP_NAME = $att_emp_name[$i]; 

					$model->ATT_DATE = $att_date[$i];

					$model->ATT_CLOCK_IN = $att_clock_in[$i];

					$model->ATT_CLOCK_OUT = $att_clock_out[$i];


				//$model->save();

				

				if ($model->save()){

					$success++;

					Yii::app()->user->setFlash('success', 'Data Berhasil Diimport :'. $success);

				}else{

					$filed++;

					Yii::app()->user->setFlash('danger', 'Data Gagal Diimport :' .$filed);

					

					/* CHtml::errorSummary($model); die(); */

				}

			}		

		

            $this->redirect(array('admin'));

        }


		$this->render('Import',array(

		'model'=>$model,

			

        ));

	}	




when i change the index value from the first for() looping or second for() looping and i am runing the import process that showing error message "Undefined offset : . . . "

i don’t know why my code is not working properly,some times when i change the index value in both of looping for same value, that just show me the failed data counter and no one data from my excel sample file is svaed into database.

i attached 2 sample of my problem below

there is shomething missing in my code??

I am really appreciate for your help… :)

thanks

hi dear i need your in my student attendance module can you help me plz.i don’t know how i make a attedence sheet in yii