slim_jimmy7 Posted March 5, 2010 Share Posted March 5, 2010 Was over at the php coding forums and ran into a dead end. Here is what I am doing, I have a text file that is exported from a game. This text file has multiple spaces in it. I want to import it and read the file and import the file contents into it. Here is my php file: //connection stuff (trust me it is correct) // tab delimited file $file = "standings.txt"; // open file $handle = fopen($file, "rb"); $contents = fread($handle, filesize($file)); // close file fclose($handle); $data = preg_split('/[,? ]+/',$contents); $eventname = $data[3]; $finishposition = $data[21]; $drivernumber = $data[23]; $drivername = $data[24]; $laps = $data[25]; $lapsled = $data[26]; $points = $data[27]; $qualposition = $data[22]; $qualtime = $data[28]; $reasonout = $data[29]; $the_query = "INSERT INTO `s1racestats` (`eventname`, `series`, `firstplace`, `finishposition`, `top10`, `top5`, `drivernumber`, `drivername`, `laps`, `lapsled`, `points`, `qual1stplace`, `qualposition`, `qualtime`, `reasonout`, `prov`, `didnotstart`, `year`) VALUES ('$eventname', 'PSRLpts', 1, $finishposition, 1, 1, $drivernumber, '$drivername', $laps, $lapsled, $points, 1, $qualposition, $qualtime, '$reasonout', 0, 0, 2010)"; mysql_query($the_query, $connection_details) or die ('Error in result: '. mysql_error()); ?> Here is the text file: Race Final North Carolina Speedway 1.017 miles 137 laps -------------------------------------------------------------------------------- Fin Str Driver Laps Led Pts Qual Reason Out -------------------------------------------------------------------------------- 1 1 38 !ECR!Mate 137 81 185 147.018 Running 2 2 50 Gabby 137 35 175 146.009 Running 3 3 133 Spoiler33 137 9 170 145.998 Running 4 5 83 fisch83 137 0 160 145.262 Running 5 11 15 SKOALMAN 137 7 160 143.514 Running 6 4 104 !Rude! 136 3 155 145.303 Running 7 8 106 (WCR)JDM106 136 0 146 144.426 Running 8 12 77 slim 135 0 142 143.508 Running 9 7 45 Ozzie 135 2 143 144.883 Running 10 14 108 Speedball57 135 0 134 Running 11 6 101 jimbob4 133 0 130 145.055 Running 12 9 51 A_Parks 59 0 127 144.164 DNF 13 10 61 !ECR!B1Racer 27 0 124 143.841 DNF 14 13 76 PSRL 0 0 121 Running Race time - 57:27.389 Average speed - 145.499mph Margin of victory - 3.374sec Caution flags - 0 # of lead changes - 7 Weather - Clear 53^ N 10mph I get-- Error in result: Unknown column 'Running' in 'field list' what we tried over on the other forum is here: http://www.phpfreaks.com/forums/index.php/topic,290070.0.html Quote Link to comment https://forums.phpfreaks.com/topic/194208-importing-text-file-problems/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 5, 2010 Share Posted March 5, 2010 Your current problem is that the variable that is receiving the 'Running' value is not what you think it is. Echo $the_query so that you can see what exactly it is. Quote Link to comment https://forums.phpfreaks.com/topic/194208-importing-text-file-problems/#findComment-1021783 Share on other sites More sharing options...
slim_jimmy7 Posted March 5, 2010 Author Share Posted March 5, 2010 As it turns out, I was four strings off. Now... I was under the impression that the regex code would pick up everything in the text file that wasn't a space. I counted time and time again, how can I be four strings off? Do the excessive dashes not count? Quote Link to comment https://forums.phpfreaks.com/topic/194208-importing-text-file-problems/#findComment-1021939 Share on other sites More sharing options...
slim_jimmy7 Posted March 5, 2010 Author Share Posted March 5, 2010 BTW, thank you for your help. I have another question in regards to this text file. The text files will vary in the number of drivers, it could be as low as two, it could be as high as 43. How would I put that together, so that I don't get many empty columns or errors? Quote Link to comment https://forums.phpfreaks.com/topic/194208-importing-text-file-problems/#findComment-1021952 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.