Page 1 of 1

Do I need an array for this?

Posted: Sun Aug 17, 2003 8:59 pm
by jkmcgrath
I am taking a text file and parsing it into strings for inserting into a MySql DB.

The first thing I have done was to see if I can actually find and put the data in a strings which I have done with the following code.

Code: Select all

<?PHP 
//read.php
$offPlayers = "./nfl.txt" ;
if (!($fp = fopen($offPlayers, "r"))) die ("Cannot open file");
$player = fgets($fp);
$player = fgets($fp);
$player = fgets($fp);
$player = fgets($fp);
do
&#123;
$fullname = fread($fp,25);
$fullname = trim($fullname);
echo "name",$fullname;
$offset = fgetc($fp);
$id = fread($fp, 4);
$id = trim($id);
echo "ID",$id;
$offset = fgetc($fp);
$team = fread($fp, 3);
$team = trim($team);
echo "Team",$team;
$offset = fgetc($fp);
$teamid = fread($fp, 4);
$teamid = trim($teamid);
echo "Team ID",$teamid;
$offset = fgetc($fp);
$pos = fread($fp, 2);
$pos = trim($pos);
echo "Posistion",$pos;
$offset = fgetc($fp);
$inj_stat = fread($fp, 1);
$inj_stat = trim($inj_stat);
echo "Injury",$inj_stat;
$offset = fgetc($fp);
$start = fread($fp, 1);
$start = trim($start);
echo "Started",$start;
$offset = fgetc($fp);
$played = fread($fp, 1);
$played = trim($played);
echo "Played",$played;
$offset = fgetc($fp);
$inact = fread($fp, 1);
$inact = trim($inact);
echo "Inactive",$inact;
$offset = fgetc($fp);
$pcmp = fread($fp, 3);
$pcmp = trim($pcmp);
echo "Completions",$pcmp;
$offset = fgetc($fp);
$patt = fread($fp, 3);
$patt = trim($patt);
echo "Attempts",$patt;
$offset = fgetc($fp);
$pyds = fread($fp, 3);
$pyds = trim($pyds);
echo "Passing Yards",$pyds;
$offset = fgetc($fp);
$pint = fread($fp, 2);
$pint = trim($pint);
echo "Interceptions",$pint;
$offset = fgetc($fp);
$ptds = fread($fp, 2);
$ptds = trim($ptds);
echo "TDS",$ptds;
$offset = fgetc($fp);
$p2pt = fread($fp, 2);
$p2pt = trim($p2pt);
echo "2points",$p2pt;
$offset = fgetc($fp);
$psck = fread($fp, 3);
$psck = trim($psck);
echo "Sacked",$psck;
$offset = fgetc($fp);
$psckyds = fread($fp, 3);
$psckyds = trim($psckyds);
echo "YDS",$psckyds;
$offset = fgetc($fp);
$car = fread($fp, 3);
$car = trim($car);
echo "carries",$car;
$offset = fgetc($fp);
$ryds = fread($fp, 3);
$ryds = trim($ryds);
echo "rushing yds",$ryds;
$offset = fgetc($fp);
$rtds = fread($fp, 2);
$rtds = trim($rtds);
echo "rushing tds",$rtds;
$offset = fgetc($fp);
$r2pt = fread($fp, 2);
$r2pt = trim($r2pts);
echo "Rush 2pts",$r2pt;
$offset = fgetc($fp);
$rec = fread($fp, 3);
$rec = trim($rec);
echo "Receptions",$rec;
$offset = fgetc($fp);
$recyds = fread($fp, 3);
$recyds = trim($recyds);
echo "Reception yds" , $recyds;
$offset = fgetc($fp);
$rectds = fread($fp, 2);
$rectds = trim($rectds);
echo "Reception tds" , $rectds;

$player = fgets($fp);
echo "<br>";
&#125;
while(!Feof($fp));
fclose($fp);
?>
For me this is 13 hours of work lol 8O And I am only 2/3rds done with this file so before I go any farther I need stop and see if I need to adjust my code.

The echo's you see in there will not be in the DB they were just so I would know I was getting the right info.

Now I am ready to insert the strings in the database but what I am unsure of is if it will automaticaly create a new record each time or just write over the same one over and over until the end.

Any help would be great.

Thanks,
John

Posted: Mon Aug 18, 2003 4:10 am
by twigletmac
Could you give us a couple of sample lines from the text file and show us the structure of the database it should be going into - if you also say what each piece of data from the text file corresponds to within the db table it would help you get the best answer for your question.

Mac

Sure

Posted: Mon Aug 18, 2003 6:12 am
by jkmcgrath
Below is a snippet of the file. I havent gotten the database built yet as I wasnt sure I could do this. Each line is to be a record in the table.

Code: Select all

; 2003 Week 00 03WK00QO.NFL   QSS Offensive Player Stats
;                                                  |--------  Passing  --------|-- Rushing --|- Receiving -|-   Kicking      FG Distances -|
;                                                                    2-                    2-            2-                  01  30  40
;Name                     ID #  Tm/ID  Pos I S P T Cmp Att Yds In TD Pt Sck/Yds Car Yds TD Pt Rec Yds TD Pt EPM EPA FGM FGA -29 -39 -49 50+ FL TDs by distance
Abdullah, Rabih           1584 CHI 9019 RB   0 1 0   0   0   0  0  0  0   0   0   0   0  0  0   0   0  0  0   0   0   0   0   0   0   0   0  0 
Aiken, Sam                2295 BUF 9000 WR   0 1 0   0   0   0  0  0  0   0   0   0   0  0  0   0   0  0  0   0   0   0   0   0   0   0   0  0 
Akers, David              1594 PHI 9016 PK   0 1 0   0   0   0  0  0  0   0   0   0   0  0  0   0   0  0  0   0   0   0   0   0   0   0   0  0 
Alexander, Dan            1993 JAC 9029 RB   0 1 0   0   0   0  0  0  0   0   0   0   0  0  0   0   0  0  0   0   0   0   0   0   0   0   0  0 
Alexander, Shaun          1754 SEA 9013 RB   0 1 0   0   0   0  0  0  0   0   0   0   0  0  0   0   0  0  0   0   0   0   0   0   0   0   0  0 
Alexander, Stephen        1504 SD  9012 TE   0 1 0   0   0   0  0  0  0   0   0   0   0  0  0   0   0  0  0   0   0   0   0   0   0   0   0  0 
Allen, Brian              2171 IND 9001 RB   0 1 0   0   0   0  0  0  0   0   0   0   0  0  0   0   0  0  0   0   0   0   0   0   0   0   0  0 
Alstott, Mike             1276 TB  9023 RB   0 1 0   0   0   0  0  0  0   0   0   0   0  0  0   0   0  0  0   0   0   0   0   0   0   0   0  0 
Andersen, Morten             9 KC  9010 PK   0 1 0   0   0   0  0  0  0   0   0   0   0  0  0   0   0  0  0   0   0   0   0   0   0   0   0  0