Do I need an array for this?
Posted: Sun Aug 17, 2003 8:59 pm
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.
For me this is 13 hours of work lol
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
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
{
$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>";
}
while(!Feof($fp));
fclose($fp);
?>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