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 Quote 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. Quote 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 />"; } } ?> Quote 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 Quote Link to comment https://forums.phpfreaks.com/topic/133565-solved-php-file/#findComment-699034 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.