Read multiple text files to update corresponding !URGENT!
Posted: Wed Oct 11, 2006 2:03 pm
I have a products/inventory MySQL table populated with item numbers, weights, images, etc. Is what I don't have is product descriptions. My product descriptions are all in seperate text (.txt) files in multiple directories. Each product's description is in its own text file named, for example, itemNumber.txt or 16000.txt. I need a PHP loop that will perform the following tasks (I think):
1. read all the file names from the directory, parse the item numbers from the names, and put them into an array
2. read the contents of each file into an array associated with the item number or file name
3. update the description field in the database with the corresponding (itemNumber) description from each text file.
The entire contents of the text file will go into the description field so no 'line by line' parsing is neccasary.
Basically I need to make the following poor example recursive as I have a lot of descriptions:
$txtFile[16000] = fopen '/products/descriptions/16000.txt';
$description = fread($txtFile[16000]);
$sql = 'UPDATE inventory SET description = ' . $description . ' WHERE itemNumber = ' . 16000; // I don't know how to come up with the itemNumber from file name here???
The above is ONLY an attempt to illustrate what I am trying to do. Also, the itemNumber needs to be parsed from the txt file's name so it can tell the query which record it belongs to.
Given enough time I could research, revisit, and learn how to accomplish this but I have NO time and need this today.
Thank you very much to anyone who can be of help!
PHP Version: 4.4.4
MySQL Version: 4.1.21-standard
Apache version: 1.3.37 (Linux)
1. read all the file names from the directory, parse the item numbers from the names, and put them into an array
2. read the contents of each file into an array associated with the item number or file name
3. update the description field in the database with the corresponding (itemNumber) description from each text file.
The entire contents of the text file will go into the description field so no 'line by line' parsing is neccasary.
Basically I need to make the following poor example recursive as I have a lot of descriptions:
$txtFile[16000] = fopen '/products/descriptions/16000.txt';
$description = fread($txtFile[16000]);
$sql = 'UPDATE inventory SET description = ' . $description . ' WHERE itemNumber = ' . 16000; // I don't know how to come up with the itemNumber from file name here???
The above is ONLY an attempt to illustrate what I am trying to do. Also, the itemNumber needs to be parsed from the txt file's name so it can tell the query which record it belongs to.
Given enough time I could research, revisit, and learn how to accomplish this but I have NO time and need this today.
Thank you very much to anyone who can be of help!
PHP Version: 4.4.4
MySQL Version: 4.1.21-standard
Apache version: 1.3.37 (Linux)