sam06 Posted November 20, 2008 Share Posted November 20, 2008 Simple really, but not sure how I would do it. I have a text file of numbers, seperated on a new line. I plan to move all these into a mysql database- how would I do this? I assume it would be a loop, and then the php file code would gather the line of data, to a variable. Than a mysql query would post this to the database, and this all would be looped. Any help on the php file split bit? Cheers, Sam Link to comment https://forums.phpfreaks.com/topic/133565-solved-php-file/ Share on other sites More sharing options...
DeanWhitehouse Posted November 20, 2008 Share Posted November 20, 2008 Give an example of how the numbers are stored. Link to comment https://forums.phpfreaks.com/topic/133565-solved-php-file/#findComment-694726 Share on other sites More sharing options...
trq Posted November 20, 2008 Share Posted November 20, 2008 <?php foreach (file('yourtextfile.txt') as $number) { $number = mysql_real_escape_string($number); $sql = "INSERT INTO tablename (fieldname) VALUES ($number);"; if (mysql_query($sql)) { echo "$number inserted successfully<br />"; } } ?> Link to comment https://forums.phpfreaks.com/topic/133565-solved-php-file/#findComment-694730 Share on other sites More sharing options...
sam06 Posted November 25, 2008 Author Share Posted November 25, 2008 Thats brilliant, sorry for the late reply. Many thanks, Sam Link to comment https://forums.phpfreaks.com/topic/133565-solved-php-file/#findComment-699034 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.