CSV File format import

 
Post new topic   Reply to topic    Aprelium Forum Index -> Databases
View previous topic :: View next topic  
Author Message
svankamon
-


Joined: 01 Apr 2007
Posts: 148
Location: Chesterfield UK

PostPosted: Thu Jan 17, 2008 11:48 pm    Post subject: CSV File format import Reply with quote

Hi i have a script that requires locations/countries inporting from a csv file format. This would save me a lot of work doing it manualy. I dont actually have a csv file of countries/town locations but have a php file in the format below. Does anyone know anything about how to change the php file i have to csv. I think excell will let me open the php file of countries and towns and then save it as csv. A portion of the php file i have is given below. If anyone knows how to change this to csv then import it to the locations table in my database id be very grateful. Thanks in advance???

This sample format is what i have for USA

"USA" => array ("
Alabama","
Alaska","
Arizona","
Arkansas","
California","
Colorado","
Connecticut","
Delaware","
Florida","
Georgia","
Hawaii","
Idaho","
Illinois","
Indiana","
Iowa","
Kansas","
Kentucky","
Louisiana","
Maine","
Maryland","
Massachusetts","
Michigan","
Minnesota","
Mississippi","
Missouri","
Montana","
Nebraska","
Nevada","
New Hampshire","
New Jersey","
New Mexico","
New York","
North Carolina","
North DaKota
Ohio","
Oklahoma","
Oregon","
Pennsylvania","
Rhode Island","
South Carolina","
South DaKota
Tennessee","
Texas","
Utah","
Vermont","
Virginia","
Washington","
Washington D.C.","
West Virginia","
Wisconsin","
Wyoming","other (USA)" ),
Back to top View user's profile Send private message Send e-mail
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Fri Jan 18, 2008 4:11 pm    Post subject: Re: CSV File format import Reply with quote

svankamon,

You could write a little function in PHP that uses that array to output a CSV file. CVS files are no more than text files with data separated by commas (,) and lines separated by a line feed character.

How should the data be in the CSV? (each country will have a variable name of locations, how are you going to show that in the table?)
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
svankamon
-


Joined: 01 Apr 2007
Posts: 148
Location: Chesterfield UK

PostPosted: Fri Jan 18, 2008 4:38 pm    Post subject: CSV Reply with quote

Hi, thanks again. The company i attained the script for is going to do it for me later today. Il look into the CSV format. Thanks.
Back to top View user's profile Send private message Send e-mail
Immemiaplaype
-


Joined: 13 Jul 2011
Posts: 13
Location: United Kingdom

PostPosted: Wed Feb 01, 2012 7:26 pm    Post subject: CSV File format import Reply with quote

CSV:
As we have already seen CSV comma-separated values format is something you may have had to deal with if you have ever worked with spreadsheets or databases..

Now lets work with the ceation of CSV file and sending the data dynamically to a csv file.The file lets you enter the contact details with name and number of the Person

Try the following ruby code for creating the CSV file

require csv

writer = CSV.opencsvfile.csv,w #Writer to open the csv file file

begin

print "Enter Contact Name: "

name =gets.chomp

print "Enter Contact No: "

num =gets.chomp

s = name" "num

row1 = s.split

writer << row1

print "Do you want to enter another record ? y/n: "

ans =gets.chomp

end while ans = "n"

writer.close

file = File.newcsvfile.csv #Creating a csv file dynamically

lines = file.readlines

parsed = CSV.parselines.to_s

p parsed

puts ""

#For displaying the data that has given

puts "Details of Contacts stored are as follows..."

puts ""

puts "-------------------------------"

puts "Contact Name Contact No"

puts "-------------------------------"

puts ""

CSV.opencsvfile.csv,r do row

puts row0 " " row1

puts ""
end


Thank you
Sai Vardhan Turimella
Back to top View user's profile Send private message Send e-mail ICQ Number
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> Databases All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group