pacome Posted February 2, 2007 Share Posted February 2, 2007 I've got a table in a word doc with some country and city codes... is there any way of inserting them all into a mysql db without going one by one? thanks! Link to comment https://forums.phpfreaks.com/topic/36796-insert-in-a-db/ Share on other sites More sharing options...
pacome Posted February 2, 2007 Author Share Posted February 2, 2007 no way??? Link to comment https://forums.phpfreaks.com/topic/36796-insert-in-a-db/#findComment-175634 Share on other sites More sharing options...
Balmung-San Posted February 2, 2007 Share Posted February 2, 2007 Just because somebody doesn't answer you in an hour doesn't mean they don't know. You have to give people some time. Anyway, I believe it would be possible with COM, however that requires your web server to be Windows, and then you have to learn proper COM usage, which is a whole other can of worms. All in all, I don't think it'd be worth the time to write a page to do it. Anybody else know if it's possible without COM? Link to comment https://forums.phpfreaks.com/topic/36796-insert-in-a-db/#findComment-175637 Share on other sites More sharing options...
pacome Posted February 2, 2007 Author Share Posted February 2, 2007 Sorry I guess sitting here in my PC made me loose my sense of time.. thanks for your help! Link to comment https://forums.phpfreaks.com/topic/36796-insert-in-a-db/#findComment-175641 Share on other sites More sharing options...
chronister Posted February 2, 2007 Share Posted February 2, 2007 You might try saving into a csv file and importing from that. I did this kind of thing for an address book I made for my wife. I exported the windows address book into a csv file and then have a script to grab the csv and import it properly. This will take a csv file with the first row being the column names, and puts it into an associative array. You will have to modify it to your needs as it simply prints out the array in the end, but its a pretty neat script. <?php $file=your_csv_file_here; //Move through a CSV file, and output an associative array for each line ini_set("auto_detect_line_endings", 1); $current_row = 1; $handle = fopen("$file", "r"); while ( ($data = fgetcsv($handle, 10000, ",") ) !== FALSE ) { $number_of_fields = count($data); if ($current_row == 1) { //Header line for ($c=0; $c < $number_of_fields; $c++) { $header_array[$c] = $data[$c]; } } else { //Data line for ($c=0; $c < $number_of_fields; $c++) { $data_array[$header_array[$c]] = $data[$c]; } print_r($data_array); } $current_row++; } fclose($handle); }; ?> I did not write this, I found it in the php manual under the comments in the fgetcsv function(I think). Thanks to the person who wrote this though. Link to comment https://forums.phpfreaks.com/topic/36796-insert-in-a-db/#findComment-175652 Share on other sites More sharing options...
pacome Posted February 2, 2007 Author Share Posted February 2, 2007 thanks to him/her and to you for passing it to me!!! Link to comment https://forums.phpfreaks.com/topic/36796-insert-in-a-db/#findComment-175657 Share on other sites More sharing options...
richardw Posted February 2, 2007 Share Posted February 2, 2007 Hopefully the post by chronister will work for you. If not I have had good luck extracting data from Word if it's in a column by using this command to exctract the column from word: Place the cursor in the upper left of the first column and then press the Shift and Alt keys together and drag to highlight your column. Cut and paste into notepad and insert the textfile into the respective field... repeat the process a few times. Another tip for data if it is in a table is to cut and paste the table into notepad, all formatting will be lost and the data should be intact. You might have to use a search & replace function to place delimiters between fields. best Link to comment https://forums.phpfreaks.com/topic/36796-insert-in-a-db/#findComment-175681 Share on other sites More sharing options...
pacome Posted February 4, 2007 Author Share Posted February 4, 2007 wow! I ' ll try this too! thanks! Link to comment https://forums.phpfreaks.com/topic/36796-insert-in-a-db/#findComment-176761 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.