If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Help with adding products to database

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-07-09, 11:13
915855 915855 is offline
Registered User
 
Join Date: Oct 2009
Posts: 6
Help with adding products to database

I am a newbie to sql so here is what I am trying to do, can somebody please help me.
I have an excel spreadsheet with 4 columns of products as listed below
1) Product Name
2) Description
3) Price
4) Link
I am using myphpadmin and I created 4 tables with the names listed above. I converted the excel file to csv and then I imported it to my database but I cannot make it to show in the right tables. Can someone please help me by telling how to do it from scratch. I do not know if when I created the tables if I used the right format for each table. If this was your project how would you create the tables and how would you upload the files (step by step instructions would be very helpful). Thank you in advance.
Reply With Quote
  #2 (permalink)  
Old 10-07-09, 14:15
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
there should be only one table, not four

CREATE TABLE products
( Name VARCHAR(55)
, Description VARCHAR(55)
, Price DECIMAL(7,2)
, Link VARCHAR(55)
);

then look up the LOAD DATA INFILE command to load your csv directly into this table
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 10-07-09, 15:07
915855 915855 is offline
Registered User
 
Join Date: Oct 2009
Posts: 6
I want to thank you for taking the time to help me. I went ahead and created the tables but when I try to import the csv file into my database, all the information is only copied into the Name field. The other tables all have NULL on them. I tried every possible way to import it but I cannot import each column to the tables that I created. This is exactly what I am doing to import the csv file.
1) I click on the IMPORT tab in myphpadmin
2) I locate the file in my hard drive and then I choose CSV USING LOAD DATA option. I leave the OPTION field the way they are because I do not know what they are for and then I press GO.
3) I get a message that it was successful but when I check my tables, only the NAME table has all the data entered on it and the other tables have NULL on them.

Please help. Thanks in advance.

Last edited by 915855; 10-07-09 at 15:11.
Reply With Quote
  #4 (permalink)  
Old 10-07-09, 17:35
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
there should be only one table, not four
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 10-07-09, 17:45
915855 915855 is offline
Registered User
 
Join Date: Oct 2009
Posts: 6
Sorry, there is one table and it has 4 fields. Can you please tell me what I am doing wrong when uploading the file.Thanks
Reply With Quote
  #6 (permalink)  
Old 10-07-09, 18:10
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Assuming your using data load command then you need to look at the field separator clause.
Reply With Quote
  #7 (permalink)  
Old 10-07-09, 18:23
915855 915855 is offline
Registered User
 
Join Date: Oct 2009
Posts: 6
Can you tell me how I would do that.Thanks
Reply With Quote
  #8 (permalink)  
Old 10-07-09, 20:12
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
You'll need to give us what you initially used to load the data plus the first few lines of the data. It would help if we had the table definition to.
Reply With Quote
  #9 (permalink)  
Old 10-07-09, 21:24
915855 915855 is offline
Registered User
 
Join Date: Oct 2009
Posts: 6
I am a newbie and you totally lost me with your question but I will try to answer it. I created the data in excel and saved it as CSV. The data has 4 columns as follows:
Column 1 = Name
Column 2 = Description
Column 3 = Price
Column 4 = Link

The table definition is the same as the one given to me by r937 which is:

CREATE TABLE products
( Name VARCHAR(55)
, Description VARCHAR(55)
, Price DECIMAL(7,2)
, Link VARCHAR(55)
);

Any help I will greatly appreciate it. Thanks.
Reply With Quote
  #10 (permalink)  
Old 10-08-09, 04:02
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
How did you import the csv file into the database?
Is there an option to set the field separator to a comma?
Reply With Quote
  #11 (permalink)  
Old 10-08-09, 08:24
915855 915855 is offline
Registered User
 
Join Date: Oct 2009
Posts: 6
I did not set an option. Can you please tell me step by step instructions on how to fill out these fields. Thanks.
Reply With Quote
  #12 (permalink)  
Old 10-12-09, 12:06
drummer79 drummer79 is offline
Registered User
 
Join Date: Oct 2009
Posts: 8
Import csv file using phpMyAdmin

-Create the database first.
-Click on the database name.
-Click the import tab.
-Browse and find the csv file you want to import- using r937 file format
-Click go.

This may help.
Reply With Quote
  #13 (permalink)  
Old 10-12-09, 13:41
drummer79 drummer79 is offline
Registered User
 
Join Date: Oct 2009
Posts: 8
Import file to database using myphpadmin

CREATE TABLE products
( Name VARCHAR(55)
, Description VARCHAR(55)
, Price DECIMAL(7,2)
, Link VARCHAR(55)
);

INSERT INTO `products`(`Name`,`Description`,`Price`,`Link`) VALUES ('Corn','Yellow Corn','$5.00','www.light.com'),
('Pepper','Hot Pepper','10.00','www.whatever.com');

Additional info.
Reply With Quote
  #14 (permalink)  
Old 10-12-09, 23:29
spraatspa spraatspa is offline
Registered User
 
Join Date: Oct 2009
Posts: 1
I agree this is exactly for the csv file:
1) I click on the IMPORT tab in myphpadmin
2) I locate the file in my hard drive and then I choose CSV USING LOAD DATA option. I leave the OPTION field the way they are because I do not know what they are for and then I press GO.
3) I get a message that it was successful.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On