My last issue at last . I have uncovered a poor logical error on my part. I hope the CSV file and being reading it in(that was the easy part).
I only want to read in the first 4 turns/players and store their data(okay that wasn't to bad either). I am using a for loop for that one. Then I use a while loop to continue reading the CSV file. And that is where my issue is. When the While loop starts to read, it starts at the top of the file(CSV). So my question is how can I read the first four lines/players info then transition into reading from line 5 to the end with out re-reading the first four lines? Here is how I currently have it set up below.
Thank you for your time!
I only want to read in the first 4 turns/players and store their data(okay that wasn't to bad either). I am using a for loop for that one. Then I use a while loop to continue reading the CSV file. And that is where my issue is. When the While loop starts to read, it starts at the top of the file(CSV). So my question is how can I read the first four lines/players info then transition into reading from line 5 to the end with out re-reading the first four lines? Here is how I currently have it set up below.
Code:
//Open file to read
$handle = fopen("YellowWins.csv", "r");
for($i = 0; $i < 4; $i++)
{
$data = fgetcsv($handle, 1024, ",");
// read in first four turns before while loop.
if($i == 0){
echo $i. " Begin <br>";
$Player_Array[0][0] = $data[0];
$Player_Array[0][1] = $data[1];
$Player_Array[0][2] = "Route One";
$Player_Array[0][3] = $RouteOne[0];
$Player_Array[0][5] = $RouteOne;
$Player_Array[0][6] = $Player1;
$whichPlayerInstance = $Player1;
Enact_Turn($data, $Player_Array,$whichPlayerInstance,$RouteTwo,$RouteThree);
}
elseif($i == 1){
echo $i. "<br>";
$Player_Array[1][0] = $data[0];
$Player_Array[1][1] = $data[1];
$Player_Array[1][2] = "Route One";
$Player_Array[1][3] = $RouteOne[0];
$Player_Array[1][5] = $RouteOne;
$whichPlayerInstance = $Player2;
$Player_Array[1][6] = $Player2;
Enact_Turn($data, $Player_Array,$whichPlayerInstance,$RouteTwo,$RouteThree);
}
elseif($i == 2){
echo $i. "<br>";
$Player_Array[2][0] = $data[0];
$Player_Array[2][1] = $data[1];
$Player_Array[2][2] = "Route One";
$Player_Array[2][3] = $RouteOne[0];
$Player_Array[2][5] = $RouteOne;
$whichPlayerInstance = $Player3;
$Player_Array[2][6] = $Player3;
Enact_Turn($data, $Player_Array,$whichPlayerInstance,$RouteTwo,$RouteThree);
}
elseif($i == 3){
echo $i. "<br>";
$Player_Array[3][0] = $data[0];
$Player_Array[3][1] = $data[1];
$Player_Array[3][2] = "Route One";
$Player_Array[3][3] = $RouteOne[0];
$Player_Array[3][5] = $RouteOne;
$whichPlayerInstance = $Player4;
$Player_Array[3][6] = $Player4;
Enact_Turn($data, $Player_Array,$whichPlayerInstance,$RouteTwo,$RouteThree);
}
else{
echo("Sorry there was a system var i problem");
}
echo "<br>" .$i. " end of for loop <br>";
}
//Open class to read csv into data
while (($data = fgetcsv($handle, 1024, ",")) !== FALSE)
{
Enact_Turn($data, $Player_Array, $whichPlayerInstance,$RouteTwo,$RouteThree);
}
echo"<br> -- END OF FILE -- ";
//close file
fclose($handle);
Thank you for your time!