|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
||||
|
||||
|
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????
|
|
#2
|
|||
|
|||
|
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. |
|
#3
|
||||
|
||||
|
Thanks Rod, could you explain in more detail how to do this as I am very new to both PHP and mySQL
|
|
#4
|
|||
|
|||
|
I sent you an email.
|
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > Importing LOTS of data into mySQL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|