Forum Moderators: open
[3]CREATE TABLE ftz_feed (
category VARCHAR(50) DEFAULT 'Other Collections');[/3] It creates a database and tables then opens and INSERTS the data from an .csv file that was produced with excel. Empty cells in the .csv file under category should populate with "Other Collections" I'm thinking. If I do an INSERT with phpmyadmin leaving the 'category' field blank it works, but not when loading the datafeed .csv file. I'm thinking that those cells in Excel that appear blank have some white space or something.
I would think you need to check for an empty value in the csv and write the INSERT differently, otherwise youll get an empty string or null value inserted.
Or, make the csv export write "Other Collection" if the field is empty and lose the default value.
HTH
CREATE TABLE ftz_feed (category VARCHAR(50) DEFAULT 'Other Collections');
INSERT INTO ftz_feed (category) VALUES(DEFAULT);
So if you have an empty column in your .csv file and you know you want it populated with the table's DEFAULT value you can specify the DEFAULT keyword.
Since you have PHP, you can make the script tweak the data before INSERTing really easiliy. Just read the .csv line by line [fopen(),fgets()], creating an INSERT statement for each one. That way, you can also tweak any other values that are not optimized for your table. It's typically bad practice to design a database table around a limited and "flat" intermediate structure like a .csv file.
Since you know what value the empty value causes [most likely a non-NULL ""], you could also perform a MySQL REPLACE on all the records that were not filled in after everything is imported. As a matter of fact, you don't really need to do anything at all, the blank field value can mean whatever you want it to implicitly -- the added benefit here is that the empty (default) values will sort first as well, and thus not be stuffed in the middle somewhere.
Your import is simple enough, unless you have a billion gazillion records, making several passes through the MySQL database to ensure data integrity is a small price to pay.