We help IT Professionals succeed at work.

import data from csv to selected rows in table

terencepires
terencepires asked
on
520 Views
Last Modified: 2010-04-21
hello,

i created a csv file containing data i want to insert in a table. I have 5 rows in the table and want to update only 4, the fifth one is in fact an auto-inc. But when using the import function, phpmyadmin tells me there is a problem at line 1 in my csv file... It works perfectly though when the number of rows in the csv matches the number of rows in the table...

Anyone knows how to do it ?

Cheers

Terence
Comment
Watch Question

Commented:
for phpmyadmin you should set "Number of records(queries) to skip from start" to 1

if you run it using load data infile :

LOAD DATA INFILE ... IGNORE 1 LINES ...

see this for details :

http://dev.mysql.com/doc/refman/5.0/en/load-data.html

Author

Commented:
so if i get you right, i should :

- sort the data in my csv file to match the order of the rows in my table
- import the csv and specify that the line 1 should be ignored

After doing this i get the same error...

Commented:
could you post few lines of your csv, and the result of  SHOW CREATE TABLE yourtable

Author

Commented:
csv lines (i used ! as an encloser) :
!54 Nude Honeys!;!(CD 62268-2)!;!3!;!27!;!cd.gif!
!Bandits Mancho!;!(2003 CD 62 278 2)!;!9!;!27!;!cd.gif!
!Retro Sexual!;!(CD 62 266 2!;!13!;!27!;!cd.gif!

SHOW CREATE TABLE result :
CREATE TABLE `temp_products` (\n  `products_name_temp` varchar(100) NOT NULL,\n  `products_model_temp` varchar(12) NOT NULL default 'ref',\n  `manufacturers_id_temp` varchar(11) NOT NULL,\n  `categories_id_temp` varchar(11) NOT NULL,\n  `product_image_temp` varchar(100) default NULL,\n  `products_id_temp` int(11) NOT NULL auto_increment,\n  `date_added_temp` timestamp NOT NULL default CURRENT_TIMESTAMP,\n  PRIMARY KEY  (`products_id_temp`)\n) ENGINE=MyISAM AUTO_INCREMENT=1050 DEFAULT CHARSET=latin1

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
thanks for that !
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.