Importing .CSV

May 15, 2009 at 13:02:57
Specs: Windows XP
I'm currently trying to setup an online store, my wholesaler provides all their product info via .CSV file. The file from my wholsaler has about 2000 items. Everything uploads correctly. Great, good...Anyhow now how do I update my .CSV without overwriting all the formatting I already did? There is pretty much two coloums I need to change that are always need updating daily: STOCK and PRICE.

I guess all I'm asking is how to take the raw .CSV from wholesaler and compare and replace the price and stock coloums of my EDITED .CSV I've been using excel to edit my csv...

I am new at this, so code examples would help !!

See More: Importing .CSV

Report •

May 18, 2009 at 09:57:18
What server technology are you using for your store?

Report •

May 18, 2009 at 10:05:04
I don't know. It doesn't matter to me what I use. It just needs to work.

Report •

May 18, 2009 at 10:36:13
Well the solution depends everything on how you implement your store. Are you trying to use just javascript?

Report •

Related Solutions

May 18, 2009 at 10:39:10
If I can easily, then yes, but I am unsure what the easiest way would be. I have found many people were use javascript to implement similar things, so I tried to go with that route. I am open for anything that works !!

Report •

May 18, 2009 at 10:58:12
Here's what you need to consider. The server sends HTML code to a client (the browser displays this HTML code on your screen). Javascript runs on the client (and has access to the HTML which was sent by the server). The .CSV file you have lives on the server or is captured 'on-the-fly' from another server (either a web server, a database server, a customer server, but a 'server' nonetheless).

It sounds like you need to update existing values. Existing values must live in a database or file system somewhere (they are served) even if it is on your desktop; in other words the existing values are persisted somewhere. Your job is to get the new values and selectively change the old values. This means that you have to interact with a server somewhere in order to get the new values into your database (which then become next time's old values).

So my question about the technology referred to are you using ASP.NET/SQL Server, PhP/MySql, PhP/local files or something else? This might sound real difficult but it's not that bad.

Report •

May 18, 2009 at 11:28:00
I think I have tried Php/local files and PhP/MySql. I have tried 3 distinct things...keep in mind that all of my data that needs updating is in an xls file which I can save as anything that excel will let me save the file as...

1. I entered my table in a mySql database and I have had success inputting that data into a table on the website...I am having trouble though with the Add to cart column within this table; I need to be able to enter code for a shopping cart form that is produced by a "paypal button". After this comes the complication of chnaging the prices easily. If you don't already know, paypal makes it easy to generate the code needed for one button, but maintaining 2000 of these buttons is very very time consuming. We update our price about every month, and to have to update manually 2000 prices seems like it would take a month to do (haha).

2. I have tried manually entering the tables I need for each webpage...this seems to be the easiest. With this way, I do not have the trouble of the add to cart column because, since the table is manually entered on the webpage, the code for the add to cart can be easily copied and pasted into the webpage and the shopping cart form would perfectly. The problem with this one the same as above...I have to update 2000 prices every month and with that 2000 paypal buttons.

3. Now I am trying the javascript way in order to create variable for my column names within the excel file so that the webpage will call the excel file and update the prices on the webpages automatically after I update the excel file.

Report •

May 18, 2009 at 11:36:26
This is why you need a server technology. javascript has no concept of files. It can, however, communicate with a server (that does understand files). It sounds to me like you need to consider the following.

Right now you are receiving updates and manually updating values in a database. Then you are copying those values from the database to an HTML generator (that creates the HTML for your web-page) or editor. Then you display the web-page to the public. When updates occur you redo the preceding.

What you want is a process whereby the data is received by a program and automatically updates the database. When someone looks at your page, the server creates the HTML dynamically and uses the data from the database to populate the page with and then displays this page.

Is this close?

Report •

May 18, 2009 at 13:05:55
sounds good to me !!

Report •

May 18, 2009 at 13:35:44
Are you trying to implement a shopping cart solution or just add functionality to an existing site? If the former then investigate (or something like it) for source code for a complete shopping cart system that uses ASP.NET 3.5 and SQL Server as a database. For this solution you'd need to find an ISP that supports .NET and SQL Server (there are tons of them). If you are adding functionality to your own site then you could link in to something like a Pay-Pal solution. Either way is going to need a database with your own data linked in and some code written. The code that needs to be written depends upon your decision for an implementation selection.

Report •

May 18, 2009 at 14:06:31
We are wanting to add functionality and we currently have Paypal Web Payments Pro which you have to add Add to cart buttons for each and every part number. It works well and this is all we need, but updating these is a pain because you have to update each one individually. This is why if their was some code that could be written that could pull the updated price from the database, it would be soo much better than what we are doing now. We have an excel file we update to a .csv file that then gets imported into a mySql database. The database uses php code which I do not know nothing about. This is the code I need to get in order to update the prices automatically.

Report •

May 18, 2009 at 14:23:36
You need php code to read from the database and create a web page on demand (when a user browses your site). You also need a database management system (DMS) to update your database from the .csv file. This could be a stand-alone program that you run whenever you get an update or you could manually update the database with changes whenever you get them. Those are the two things you need to decide on. 1) automate the website to be database driven; 2)pick a DMS strategy that makes sense for you.

For #1 you'll need a website developer to design the system and write the code (either from what you've got, from scratch or customize some free-ware) because there could be a lot of it and you'd like to write it once and forget about it.

For #2 the solution will be for you to decide which approach makes the most business sense. If you've got hundreds of updates per day/week/month/year and it is time consuming then automate it. If it is more economical to manually update the database then stick with that.

I hope this helps. For anyone to help you with code they'll need a lot more detailed information like what is the schema of the tables in the database?, how many items are you setting up?, what is the frequency of change?, will there ever be anything other than .CSV formats?...etc.

Report •

May 21, 2009 at 07:06:52
How do I find the schema of the tables in the database ? There are about 2000 items to be setup with approximately 75 columns total, but some of the columns are not used on some products, and other columns are used on other products. We update prices approximately every month on average. For right now, we will be sticking to a csv format unless another format is easier to work with. Like I said before, we have an excel worksheet that is in and we can manipulate it the easiet way possible.

Report •

May 21, 2009 at 10:04:12
What database are you using? 75 columns sounds like a lot of columns. Don't you have basically, Part #, Price, Description? That's 3 columns.

Report •

May 21, 2009 at 10:32:31
Yes, we have those three columns, but we also have manufacturer specifications of our products as well.

Report •

May 21, 2009 at 12:48:48
You asked how to view the table schema. Have you found an answer yet?

Then tell me wkat you've got. Also!!! Are your web pages written in HTML or php?

Report •

May 21, 2009 at 13:25:55
If it's php / mysql, you know the table name and column names, the csv file is plain text, and you have data file access rights, then it may be fairly easy to update.

As a real basic example, say a mysql database has 8 columns and the csv file has the following attributes.


With php you can open the csv file and split each line using the comma.

$fh = @fopen("sample.csv", "r");
if($fh) {
   while(!feof($fh)) {
      $buf = split(",", fgets($fh));
       // $buf becomes an array with 8 elements
      if(count($buf) == 8) {
         $res = mysql_query("update table set
... where primaryID=$buf[0];") or die(mysql_error());
      } else {
         // error processing line in csv file
} else {
   // error opening csv file

How you'd update the database would depend on how the csv file is formatted and which fields represent what column names...

If you don't know what the column name / types are, then you can dump them to a file if you have the describe privilege.


   $lnk = mysql_connect("database host", "user", "passw");
   if(!$lnk) { die(mysql_error()); }
   if(!mysql_select_db("database name")) { die(mysql_error()); }

   $res = mysql_query("describe table_name;")
          or die(mysql_error());
   if(is_resource($res)) {

      $fh = @fopen("db_details.txt", "w");
      if($fh) {
         while($row = mysql_fetch_assoc($res)) {
            foreach($row as $key => $val) {
               fwrite($fh, $key . " = " . $val . "\n");
            fwrite($fh, "\n");



For the above, you'll need to know the database host, the user name, the password assigned to the user name, and the database name. If you don't know them, then they should be available somewhere in cpanel or whatever your web host offers you, or you may have to write a support ticket or email tech support of your web hosting company to find out.

If you don't know the table name, then you can change the query to "show tables;" (you'd need to modify the code above to remove the file routine and use echo $key . " = " . $val . "<br />"
) or use phpmyadmin from within your cpanel or whatever your hosting company provides you with.

Hope that helps and good luck.

My work in progress. I hate JS. :P

Report •

May 21, 2009 at 14:10:58
Now how about some code to read the database and insert the approximately 2000 "Buy Me" buttons he presently has to manually add to his web pages?

Report •

May 26, 2009 at 09:35:41
As far as the database schema, are you wanting the column names as well as what the type, collation, attributes, null values are ?

I found this from phpMyadmin...let me know if this helps

Report •

Ask Question