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... Quote Link to comment 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. Quote Link to comment 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 } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.