MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL 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 Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old June 5th, 2000, 04:14 PM
alexgreg's Avatar
alexgreg alexgreg is offline
Full Access
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jun 2000
Location: London, UK
Posts: 2,019 alexgreg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 sec
Reputation Power: 11
I am planning on migrating a load of names listings to a mySQL database (currently at http://www.building-trade.com/search.htm). The problem is, there are over 14,000 records to be added! I already have them saved in HTML format with each record occupying one table row and each field occupying one table cell. Is there any way to move all this data easily into a mySQL database? Currently the only way I see of doing it is by copying and pasting each of the fields out of the HTML page and into a form! This would take over 56 man hours: is there a simpler way????

Reply With Quote
  #2  
Old June 5th, 2000, 05:19 PM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
You could use PHP to parse the HTML page to break out the components. You could use regex but the string functions should be enough. First read in the file to a variable using the fopen, etc. and place into a variable, call it $html.

$table=explode('able>',$html);

The above will result in a 3 element array (assuming 1 table on the page, if not just adjust accordingly) with the 0th element holding everything through <table>, the first element everything after <table> and through </t(able> and the last holding everything after the </table>, note that only the </t of </table> will remain after the split. Use substr() to remove that. Now explode on 'r>' (assuming you don't have any other html tags inside the table ending in 'r' besides <tr> or </tr>.) This will give you an array holding the table rows (which will become records) each ending in the </t of </tr>. Again remove the last 3 characters of each element (check out array_walk() function to help with that).

Now set up a loop to split each element of that array exploding on 'd>', giving you another array which will hold the individual cells of the row your loop is currently on. Strip off the last three characters of each element ('</t' from </td> ) and then insert into the database. Once the loop completes all rows in the table will be transformed into database records with the individual cells of each row the corresponding fields of the record.

Reply With Quote
  #3  
Old June 6th, 2000, 10:48 AM
alexgreg's Avatar
alexgreg alexgreg is offline
Full Access
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jun 2000
Location: London, UK
Posts: 2,019 alexgreg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 sec
Reputation Power: 11
Thanks Rod, could you explain in more detail how to do this as I am very new to both PHP and mySQL

Reply With Quote
  #4  
Old June 6th, 2000, 04:01 PM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
I sent you an email.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Importing LOTS of data into 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