Forum Moderators: coopster
help
[webmasterworld.com...]
the log file look like this ...
05/09/2005 11:59 AM 720 perwin.cmd
05/09/2005 06:34 PM 122 mwymore.cmd
05/10/2005 10:11 AM 116 erik.cmd
05/10/2005 10:18 AM 116 tung.cmd
05/10/2005 10:24 AM 122 dhodges.cmd
05/10/2005 10:42 AM 120 vipulb.cmd
05/10/2005 10:57 AM 122 tderose.cmd
05/10/2005 11:17 AM 118 donby.cmd
05/10/2005 01:33 PM 120 raviup.cmd
05/10/2005 02:11 PM 120 shelly.cmd
05/10/2005 02:22 PM 295 balar.cmd
05/10/2005 02:27 PM 124 cantrell.cmd
05/10/2005 02:52 PM 124 tserrata.cmd
05/10/2005 03:18 PM 122 rpotral.cmd
05/10/2005 04:39 PM 120 ramkib.cmd
05/11/2005 06:44 AM 120 giulia.cmd
05/11/2005 11:13 AM 124 varghese.cmd
05/11/2005 11:20 AM 124 rajasree.cmd
05/11/2005 05:01 PM 124 jessicaz.cmd
05/05/2005 02:00 PM 58 joel.cmd
05/05/2005 02:39 PM 120 pentek.cmd
05/06/2005 09:20 AM 124 ramkumar.cmd
05/06/2005 09:28 AM 122 wctseng.cmd
05/06/2005 10:09 AM 60 bboike.cmd
05/06/2005 10:13 AM 122 susanhu.cmd
05/06/2005 10:23 AM 122 shankha.cmd
05/06/2005 10:44 AM 120 scotts.cmd
05/06/2005 10:52 AM 122 rajeshk.cmd
05/06/2005 11:04 AM 120 mnchua.cmd
05/06/2005 11:09 AM 118 jsjou.cmd
05/06/2005 11:37 AM 118 zwong.cmd
05/06/2005 11:47 AM 124 kwanthai.cmd
05/06/2005 12:03 PM 122 kjensen.cmd
05/06/2005 12:56 PM 116 yong.cmd
05/06/2005 03:01 PM 122 oropeza.cmd
05/06/2005 04:26 PM 118 ncaro.cmd
05/12/2005 03:07 PM 124 plnguyen.cmd
05/12/2005 06:08 PM 114 rau.cmd
05/12/2005 11:03 PM 124 krithika.cmd
05/13/2005 07:50 AM 124 michaelt.cmd
05/13/2005 08:06 AM 122 amitabh.cmd
so it should 1st sort it my date and year and then for the for like year 2005, what ever weeks r in the file, it should give output like if the dates fall in week 23 of the year 2005 it should give week 23 = number of user 20 etc..
can anyone help me adhieve this thing. god this seems too hard for a begineer of php like me.
OK, I'll help you over this hump, but you have to read through this code snippet and understand how it works...
function cmp($a, $b) {
// This will make it sort on the first index of the array;
// remember, arrays start with zero (0)!
$column_to_sort_on = 0;
$datea = explode('/', $a[$column_to_sort_on], 3);
$datea = $datea[1] . '/' . $datea[2] . '/' . $datea[0];
$dateb = explode('/', $b[$column_to_sort_on], 3);
$dateb = $dateb[1] . '/' . $dateb[2] . '/' . $dateb[0];
if ($datea == $dateb) return 0;
return ($datea < $dateb)? -1 : 1;
}
// Read the file, print a before snapshot, sort, print after snapshot:
// READ FILE IN:
$filename = "paultesting.txt";
$id = fopen($filename, "r");
while ($data = fgetcsv($id, filesize($filename)," "))
$table[] = $data;
fclose($id);
// BEFORE:
$before = "<table>\n";
foreach($table as $row) {
$before .= "<tr>";
foreach($row as $data) {
$before .= "<td>$data</td>";
}
$before .= "</tr>\n";
}
$before .= "</table>\n";
// SORT:
usort($table, "cmp");
// AFTER:
$after = "<table>\n";
foreach($table as $row) {
$after .= "<tr>";
foreach($row as $data) {
$after .= "<td>$data</td>";
}
$after .= "</tr>\n";
}
$after .= "</table>\n";
?>
<html><head><title>usort</title></head>
<body>
<h1>usort</h1>
<h4>Before:</h4>
<?php print $before;?>
<h4>After:</h4>
<?php print $after;?>
</body>
</html>