I'm trying to avoid using MySQL by using my CSV file on the server. I need to pull out my students information from each class based on their age. I've been reading about the use of 'fgetscsv' but would not know how to apply it.
Here's how the csv file looks like
(TEACHER,AGE,SUBJECT,NAME)
MS James,10,math,john
MS James,10,math,jamie
MS James,9,english,judy
MS James,10,english,jordan
MS James,9,english,david
MR Henington,10,english,tina
MR Henington,9,math,mike
MR Henington,9,math,mathew
Example:
I'm trying to echo only rows that has students that are 10 years old to come out like this:
"
Hi I'm John and I'm 10 years old. My favorite subject is math
Hi I'm Tina and I'm 10 years old. My favorite subject is english
etc.
"
Here's what I have.
echo "<table>";
$handle = fopen("students.csv", "r");
$data = fgetcsv($handle, 1000, ",");data rows:
$thisRow = 1;
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{if($thisRow++ % 2 == 0){$bg = "#DEF0C2";}
else{$bg = "#E9F5D6";}$teacher=$data[0];
$age=$data[1];
$subject=$data[2];
$name=$data[3];echo "<tr style='background-color: $bg'>";
echo "<td>Hi I\m $name and I\'m $age years old. My favorite subject is $subject.</td>";
echo "</tr>\n";
}
echo "</table>\n";
Any help would be great.