chanchelkumar Posted February 18, 2008 Share Posted February 18, 2008 Hi all, I am trying with some data, which i get in a txt file separated with coma (,) . i want this to insert into the database. the data is bulk... means it contains some 100 lines.. so i want to read the file and insert it to the database.. please help me... thanks in advance... Link to comment https://forums.phpfreaks.com/topic/91658-how-to-export-values-from-an-txt-file/ Share on other sites More sharing options...
PHP Monkeh Posted February 18, 2008 Share Posted February 18, 2008 $file = file_get_contents("your_text_file.txt"); $contents = explode(",", $file); // Creates an array of values for($i=0; $i<count($contents); $i++) { // Use your mysql_query() here to insert the value of $contents[$i] to the database } Although that'll only work if you have 1 column of data within the text file you're wanting to insert. Link to comment https://forums.phpfreaks.com/topic/91658-how-to-export-values-from-an-txt-file/#findComment-469438 Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 just a quick note: in FOR loops any function within the parameters (eg count()) get executed on every loop, it would be less intensive if you saved the count to a variable, eg: $x = count($contents); for($i=0; $i<$x; $i++) { // Use your mysql_query() here to insert the value of $contents[$i] to the database } Link to comment https://forums.phpfreaks.com/topic/91658-how-to-export-values-from-an-txt-file/#findComment-469440 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.