View previous topic :: View next topic |
Author |
Message |
svankamon -
Joined: 01 Apr 2007 Posts: 148 Location: Chesterfield UK
|
Posted: Thu Jan 17, 2008 11:48 pm Post subject: CSV File format import |
|
|
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 |
|
|
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
Posted: Fri Jan 18, 2008 4:11 pm Post subject: Re: CSV File format import |
|
|
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 |
|
|
svankamon -
Joined: 01 Apr 2007 Posts: 148 Location: Chesterfield UK
|
Posted: Fri Jan 18, 2008 4:38 pm Post subject: CSV |
|
|
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 |
|
|
Immemiaplaype -
Joined: 13 Jul 2011 Posts: 13 Location: United Kingdom
|
Posted: Wed Feb 01, 2012 7:26 pm Post subject: CSV File format import |
|
|
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 |
|
|
|
|
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
|
|