astralaaron Posted November 9, 2008 Share Posted November 9, 2008 i have a text file with a list if data similar to this:TESTz,TESTx,TEST1TESTs,TESTa,TEST2TEST3,TESTv,TEST3TEST5,TEST2,TEST4is there a way to load the text file into a php file, explode at the comma's and insert each row into a mysql table? Link to comment Share on other sites More sharing options...
MinusMyThoughts Posted November 9, 2008 Share Posted November 9, 2008 You could try something like this: $data = explode(',',$list_of_info);$numrows = count($data);$sql = 'INSERT INTO table_name VALUES ';$i = 1;foreach($data as $entry) { $sql .= "('$entry')"; if($i<$numrows) $sql .= ", "; $i++;}if(!mysql_query($sql)) die(mysql_error()); That's assuming the data only has one value per entry. If not, it'll be more complicated than that.-Jason Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.