Hi All,
I'm after a little bit of php help please.
I need to import a text file, sort it by the points column, then extract the top 5 points along with the name.
i.e
001,M Almunia,Arsenal,5.0,13
001,L Fabianski,Arsenal,2.5,0
001,S Taylor,Aston Villa,2.5,0
013,B Friedel,Blackburn,4.0,-1
017,A Al Habsi,Bolton,1.5,0
020,J Jaaskelainen,Bolton,3.0,0
024,P Cech,Chelsea,5.5,8
027,C Cudicini,Chelsea,2.5,0
031,T Howard,Everton,5.0,-2
Would return
M Almunia 13
P Cech 8
L Fabianski 0
S Taylor 0
J Jaaskelainen 0
This is the code I have tried, works if i use a static name instead of a variable ($keepername) but i need it to be dynamic.
Thanks
Steve
I'm after a little bit of php help please.
I need to import a text file, sort it by the points column, then extract the top 5 points along with the name.
i.e
001,M Almunia,Arsenal,5.0,13
001,L Fabianski,Arsenal,2.5,0
001,S Taylor,Aston Villa,2.5,0
013,B Friedel,Blackburn,4.0,-1
017,A Al Habsi,Bolton,1.5,0
020,J Jaaskelainen,Bolton,3.0,0
024,P Cech,Chelsea,5.5,8
027,C Cudicini,Chelsea,2.5,0
031,T Howard,Everton,5.0,-2
Would return
M Almunia 13
P Cech 8
L Fabianski 0
S Taylor 0
J Jaaskelainen 0
This is the code I have tried, works if i use a static name instead of a variable ($keepername) but i need it to be dynamic.
Code:
<?php
$handle = fopen("Goalkeepers.txt", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
$row++;
$cname=1;
$cclub=2;
$ccost=3;
$cpoints=4;
$keepername=$data[$cname];
$keeperclub=$data[$cclub];
$keepercost=$data[$ccost];
$keeperpoints=$data[$cpoints];
$goalkeepertable=array( $keepername => $keeperpoints,);
}
fclose($handle);
arsort($goalkeepertable);
$gk=0;
foreach($goalkeepertable as $name1 => $points1){
$gk++;
if ($gk==1){
$goalkeeper1= $name1;
$gpoints1 = $points1;}
echo $name1."<br ?>";
}
?>
Thanks
Steve