I have a number of text files that I need to open, then allocate certain fields to set strings inside PHP to eventually write into MySQL.
Each txt file does have the same unique value for app_id, eg
So text file 1 has
app_id name description
text file 2 has
app_id category
text file 3 has
app_id price
I want to get name, description, category and price for each record, and write that into mysql.
I can read the first one using code :
$fp = fopen('textfile1','r');
if (!$fp) {echo 'ERROR: Unable to open file.</table></body></html>'; exit;}
while (!feof($fp)) {
$line = stream_get_line($fp,4096,$eoldelimiter);
if ($line[0] === '#') continue; //Skip lines that start with #
$field[$loop] = explode ($delimiter, $line);
list($app_id, $name, $description) = explode($delimiter, $line);
$fp++;
}
fclose($fp);
?>
My question is how to read the 2nd and 3rd files? Can I somehow do it in parallel, or do I need to finish reading text file 1, write each line into mysql then open text file 2 and write category into mysql using replace on the app_id key, then do the same with text file 3 opening and ?
regards,
Greg