Import records not working with csv file, works copy/paste

A place for users and developers of the Xataface to discuss and receive support.

Import records not working with csv file, works copy/paste

Postby JR_Dev » Thu Mar 24, 2011 11:55 am

Hello,

I have a csv file that will not import correctly when browsing for the file and clicking submit. It does import correctly if I copy and paste all the data in chunks to import(One shot via the copy and paste doesn't work either). The size for the file is 80kb which is under the max limit set by php. I've double and triple checked the columns to make sure its correct with the db.

Here is the error from php:
Notice: Undefined offset: 1 in /home/rodriguez3/public_html/Macro_Express_IRU/tables/orbitInventory/orbitInventory.php on line 18

Warning: Cannot modify header information - headers already sent by (output started at /home/rodriguez3/public_html/Macro_Express_IRU/tables/orbitInventory/orbitInventory.php:19) in /home/rodriguez3/public_html/xataface-1.2.6/actions/import.php on line 48

sample data:
Code: Select all
UNET,Oldsmar IRU,OD1,OD1_BIL,0,4,1,2,1,3,1,1,0,0,13,0,0,0,0,0,0,0,0,0,0,0,0,0
UNET,Oldsmar IRU,OD1,OD1_CHMO,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0
UNET,Oldsmar IRU,OD1,OD1_COR,1,164,229,177,128,125,14,8,1,0,847,0,6,2,0,0,1,0,0,0,0,9,0,0
UNET,Oldsmar IRU,OD1,OD1_EXE,0,4,0,1,1,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0
UNET,Oldsmar IRU,OD1,OD1_FOR,0,7,36,9,6,2,1,0,0,1,62,0,0,0,0,0,0,0,0,0,0,0,0,0


Import Filter
Code: Select all
<?php
   class tables_orbitInventory
   
{
      

      
   
   //function to import csv data into tables
   
   function __import__csv(&$data, $defaultValues=array())
   
      {
      
         //build an array of dataface_record objects
      
         $records = array();
      
      

         //split the csv file into many rows
      
         $rows = explode("\n", $data);
      
      

         foreach ($rows as $row)
      
         {
         
            //iterate through rows to parse data
         
            list($platform,$area,$office,$que,$age1,$age2,$age3,$age4,$age5,$age6,$age7,$age8,$age9,$age10,$age110,$age11,$age12,$age13,$age14,$age15,$age16,$age17,$age18,$age19,$age20,$age1120,$age2159,$age60) = explode(',', $row);
         print_r($row);
         print_r("<br />");
   
         

            $record = new Dataface_Record('orbitInventory', array());


         
   //insert default values
         
            $record->setValues($defaultValues);


         
   //now we add the values from the csv file
         
            $record->setValues(
array(
            
'platform' =>$platform,
            
'area' => $area,
               
            'office' => $office,
               
            'que' => $que,
               
            'age1' => $age1,
               
            'age2' => $age2,
               
            'age3' => $age3,
               
            'age4' => $age4,
               
            'age5' => $age5,
               
            'age6' => $age6,
               
            'age7' => $age7,
               
            'age8' => $age8,
               
            'age9' => $age9,
               
            'age10' => $age10,
               
            'age110' => $age110,
               
            'age11' => $age11,
               
            'age12' => $age12,
               
            'age13' => $age13,
               
            'age14' => $age14,
               
            'age15' => $age15,
               
            'age16' => $age16,
               
            'age17' => $age17,
               
            'age18' => $age18,
               
            'age19' => $age19,
                  
            'age20' => $age20,
               
            'age1120' => $age1120,
                  
            'age2159' => $age2159,
               
            'age60' => $age60,)
               
            );
         
         

            //now add the record to the output array
         
            $records[] = $record;
               
      
         }
      
      

      //Now we return the array of records to be imported
      
      return $records;
   
   }
   
}
?>


Any ideas on how to resolve this and what could be causing the errors?

Thanks,
Juan
JR_Dev
 
Posts: 5
Joined: Wed Mar 16, 2011 10:52 am

Re: Import records not working with csv file, works copy/paste

Postby shannah » Fri Mar 25, 2011 10:49 am

What is on line 18 of orbitInventory.php?
When I copy and paste the code into my editor it shows nothing on that line..

Try some debugging echo statements and various parts to see what data is even getting through to your function.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Import records not working with csv file, works copy/paste

Postby JR_Dev » Fri Apr 01, 2011 4:42 am

Hello,

I figured out that its just the size of the data being imported that is throwing it off. I'm able to import with phpmyadmin with no problem. The csv file contains like 6,000 lines of data, so its timing out and throwing errors with Xataface. Changing the php settings hasn't helped either.

I read in another forum that you were gonna put together an example on how to import large files with mysql "LOAD DATA INFILE", is that posted anywhere? I would really like to modify the code on the import page so its seamless for the user.

Lastly, can you add a css sheet just for the left_column and main_column of a template that overrides Dataface_Main_Template? I'm using some YUI components and its adjusting elements in the header and footer that I would like to keep as is. I'm currently putting in the csss for Yui via the table's delegate class. Any ideas?

Thanks,
Juan
JR_Dev
 
Posts: 5
Joined: Wed Mar 16, 2011 10:52 am

Re: Import records not working with csv file, works copy/paste

Postby shannah » Fri Apr 01, 2011 7:31 pm

I read in another forum that you were gonna put together an example on how to import large files with mysql "LOAD DATA INFILE", is that posted anywhere?

I don't think there's an example anywhere.

If it is simply the size of the file that is the problem, I find it strange that it would work but copy/paste and not file upload. Are you sure the file upload max size settings are high enough?

Lastly, can you add a css sheet just for the left_column and main_column of a template that overrides Dataface_Main_Template? I'm using some YUI components and its adjusting elements in the header and footer that I would like to keep as is. I'm currently putting in the csss for Yui via the table's delegate class. Any ideas?


CSS is flexible enough to target just about anything you want on a page. E.g. to target tables in only the left column, you would use a rule like
Code: Select all
#left_column table {
   ...
}



-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Import records not working with csv file, works copy/paste

Postby rich » Thu Jun 02, 2011 3:06 pm

Hi. First sorry for my english it is poor...
I have the same problem. I can not import from CSV or Excel. And there are only two rows to import so the size is not the problem. I follow the wiki examples but no result if i try to import from a file. If i copy/paste the two rows on the textarea then no problem.
Any idea?
Tanks a lot. Bye.
rich
 
Posts: 2
Joined: Thu Jun 02, 2011 2:48 pm

Re: Import records not working with csv file, works copy/paste

Postby rich » Tue Jun 14, 2011 10:29 am

Hi.
My problem is solved. I forgot begin the script with '<?php', i wrote only '<?'.
Thnaks.
rich
 
Posts: 2
Joined: Thu Jun 02, 2011 2:48 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 20 guests

Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved