database - category text file to php array with explode -
i need import large category .txt file mysql database. text file has categories 3 levels.
my text file likes example below (+/- 362 entries):
business business = business innovation & ideation = innovation business = economics business = economics = global economics
my database table structure:
| id | cat | sub_cat | sub_sub_cat |
what want do, insert categories in database php. separator between cat, sub , sub_sub cat '='. want reach loop insert data database.
thanks in advice.
with kind regards,
nicky
$lines = file('category.txt'); // slurp file , split array lines foreach($lines $line) { $parts = explode('=', $line); // decompose line individual sections $cat = mysql_real_escape_string(trim($parts[0])); // prepare sections sql $subcat = mysql_real_escape_string(trim($parts[1])); $subsubcat = mysql_real_escape_string(trim($parts[2])); $sql = "insert yourtable (cat, sub-cat, sub_sub_cat) values ('$cat', '$subcat', '$subsubcat');"; mysql_query($sql) or die(mysql_error()); }
Comments
Post a Comment