Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old January 22nd, 2003, 09:33 AM
jonathen jonathen is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Essex, UK
Posts: 44 jonathen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Non-CSVtextfile dump to mysql

Hi all,

Anyone know of any shareware or scripts out there that can take a textfile of addresses which has not got the column headings in it (non-csv, just entry after entry, and not in rows), and be able to dump all data to existing table by asking what line should dump to which column?

It would save me SO much time!

TIA

Reply With Quote
  #2  
Old January 23rd, 2003, 02:35 AM
DaemonJ DaemonJ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Jamestown, TN USA
Posts: 61 DaemonJ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Non-CSVtextfile dump to mysql

If I understand your post correctly, the file looks like:

Joe User
Some company
123 Main Street
Apt 2A
Somewhere
CA
90210

or something like that?

If that is the case, are there always the same number of lines for each address with blank lines in place for missing data?

If so, you should be able to write such a script in a short time.

Reply With Quote
  #3  
Old January 27th, 2003, 10:51 AM
jonathen jonathen is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Essex, UK
Posts: 44 jonathen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Non-CSVtextfile dump to mysql

Hi,

Thanks for the reply - sorry for the delay in replying, been so busy. Yes, that's it exactly; every entry has the same number of lines. So...do you have any idea of what syntax I'd need for such a script?

TIA

Reply With Quote
  #4  
Old January 27th, 2003, 12:34 PM
xs0 xs0 is offline
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Ljubljana, Slovenia
Posts: 760 xs0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Non-CSVtextfile dump to mysql

Something like what follows should work. Note that you'll have to modify it to fit your data and database. I'll also assume that the data is in the exact format posted above.
php Code:
Original - php Code
  1.  
  2. <?php
  3.  
  4. // first, connect to database
  5. mysql_connect("localhost", "username", "password");
  6. mysql_select_db("mydatabase");
  7.  
  8. // then, open the file
  9. $infile=fopen("myfile.txt", "r");
  10.  
  11. // and then, until we reach the end of file, read the data
  12. while (!feof($infile)) {
  13.     $name=addslashes(trim(fgets($infile, 1000)));
  14.     $company=addslashes(trim(fgets($infile, 1000)));
  15.     $address1=addslashes(trim(fgets($infile, 1000)));
  16.     $address2=addslashes(trim(fgets($infile, 1000)));
  17.     $city=addslashes(trim(fgets($infile, 1000)));
  18.     $state=addslashes(trim(fgets($infile, 1000)));
  19.     $zipcode=addslashes(trim(fgets($infile, 1000)));
  20.    
  21.     // finally, insert the data into database
  22.     mysql_query("INSERT INTO mytable(name,company,address1,address2,city,state,  zipcode) VALUES ('$name', '$company', '$address1', '$address2', '$city', '$state', '$zipcode')");
  23. }
  24. ?>


To match with your data/table, modify the number of lines read for each entry and the order and names of fields in the table in your database inside the mysql_query statement. If you're not using MySQL, you'll also need to change the database calls, but the principle stays the same...

Hope this helped.

Reply With Quote
  #5  
Old January 27th, 2003, 02:32 PM
jonathen jonathen is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Essex, UK
Posts: 44 jonathen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Non-CSVtextfile dump to mysql

Thank you for that, it is greatly appreciated

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Non-CSVtextfile dump to mysql


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway