Extraction of data from textfile into mysql/php

Hi,

I’m a noobie in PHP/mySQL, and I’m still in a learning process. I have a textfile located on the desktop, and I want to extract the data from it and put these data into my database.
My data in the code is in this format in the text file:

2011/10/16 18:00
Total sum: 60

My objective is to put these data into my database table in “Date Time Sum”

Anyone got any idea of a sample source code for this, thank you!!!

Regards,
Eugene

can u post at about 15 lines from your text file ?

you should do like this,but to explode and select variables correctly

[php]
$file_handle = fopen(“test.txt”, “rb”);
while (!feof($file_handle) )
{

$line_of_text = fgets($file_handle);
$parts = explode(’ ', $line_of_text);

mysql_query("INSERT INTO table(Date, Time, Sum) VALUES(’$parts[0]’,’$parts[1]’,’$parts[2]’) ")
or die(mysql_error());
}
[/php]

Thanks! :smiley: It works!

But I have another question, what if my data are separated into 2 row or 3 rows?

For example,

Date Time Classroom

Lessons Break

as seen in a .text file?

Thanks!

Sponsor our Newsletter | Privacy Policy | Terms of Service