Search found 12 matches

by sfresher
Wed Jan 28, 2009 7:00 pm
Forum: PHP - Code
Topic: Parse a text file and then do MySQL insert?
Replies: 3
Views: 286

Re: Parse a text file and then do MySQL insert?

Can someone please help?
by sfresher
Wed Jan 28, 2009 1:24 pm
Forum: PHP - Code
Topic: Parse a text file and then do MySQL insert?
Replies: 3
Views: 286

Re: Parse a text file and then do MySQL insert?

Thanks for your advice. I will update the code accordingly. The error is column SSN in table action always shows as blank. Just had a quick look - you say it does not work, what happens? any errors? In regards to optimisation dont do this... for($i=1; $i<sizeof($fcontents); $i++) // calculates the l...
by sfresher
Tue Jan 27, 2009 2:48 pm
Forum: PHP - Code
Topic: Parse a text file and then do MySQL insert?
Replies: 3
Views: 286

Parse a text file and then do MySQL insert?

I am trying to parse 2 files and then insert data to MySQL database. The two files are "action.txt" and "status.txt", and they are corresponding to 2 tables that match the name. Column "SSN" is primary key of table people, and the foreign key in table action. For exampl...
by sfresher
Wed Jan 21, 2009 4:27 pm
Forum: PHP - Code
Topic: Parse a text file?
Replies: 17
Views: 828

Re: Parse a text file?

nor0101's code still does not work in my case. I tried to debug but can't get a clue. It seems it's better to use implode() during SQL insert.

Can someone help with a complete code?
by sfresher
Thu Jan 15, 2009 2:01 pm
Forum: PHP - Code
Topic: Parse a text file?
Replies: 17
Views: 828

Re: Parse a text file?

Thanks! But I am afraid of that your code does not work out for my case because: 1. The text data file may come with more or less data fields. e.g. Date|Time|First name|Last name|Notes|Result Date|First name|Notes|Extra field 2. The text data file may come with different order of the fields. e.g. Da...
by sfresher
Thu Jan 15, 2009 1:41 pm
Forum: PHP - Code
Topic: Parse a text file?
Replies: 17
Views: 828

Re: Parse a text file?

Can you please expend the code into parsing the file with expode()?
by sfresher
Thu Jan 15, 2009 1:16 pm
Forum: PHP - Code
Topic: Parse a text file?
Replies: 17
Views: 828

Re: Parse a text file?

I feel I am really kind of dumb in coding this in a php script. And I do learn things from others sample script. Can someone please provide a complete code so I can start learning from there?
by sfresher
Tue Jan 13, 2009 4:10 pm
Forum: PHP - Code
Topic: Parse a text file?
Replies: 17
Views: 828

Re: Parse a text file?

If you do something like this....   $data = file('FILENAME'); echo $data[0]; // this will be the header row   Once in an array you can loop through each row and create the insert query. Is this going to be a frequently used script, does efficiency need to be considered or is it a one off? I see now...
by sfresher
Tue Jan 13, 2009 3:18 pm
Forum: PHP - Code
Topic: Parse a text file?
Replies: 17
Views: 828

Re: Parse a text file?

jaoudestudios wrote:Try file. It will read the file into an array.
Documentation...http://uk2.php.net/file
Thanks! But if I use file to read the entire file into a single array, how do I read the first line only (header record)?
by sfresher
Tue Jan 13, 2009 3:02 pm
Forum: PHP - Code
Topic: Parse a text file?
Replies: 17
Views: 828

Re: Parse a text file?

jaoudestudios wrote:Just checking.

Read the file into an array, then explode it on the pipe (|) and build the query dynamically.
I am really having difficulties reading the file. I tried use fgets() but seems doesn't work for me. Can someone provide the code to work me through?
by sfresher
Tue Jan 13, 2009 2:32 pm
Forum: PHP - Code
Topic: Parse a text file?
Replies: 17
Views: 828

Re: Parse a text file?

We can't use CSV because using "|" delimited text file is a team agreement.
jaoudestudios wrote:Can you get a version of the file that is separated by commas (,). That way it would be a CSV.
by sfresher
Tue Jan 13, 2009 1:41 pm
Forum: PHP - Code
Topic: Parse a text file?
Replies: 17
Views: 828

Parse a text file?

I was trying to parse a text file and then insert the data into MySQL. I am new to php and I have checked php manual and but still cannot generate some useful code. The file contains a line of header records as follows: Date|Time|First name|Last name|Notes|Result 20081210|231053|Jack|Hendreson|Speci...