Hi. I use a click track script that generates logs but gives you no way to view them. Hey, it was free and easy. I am trying to get a numeric sort on the order of popularity of a file name was clicked. There are two files, log.txt and count.txt.
Format of count.txt
songname.mp3 - 1 - 2004-11-22 (20:27) - 2004-11-22 (20:27) - 1101176826 - 1101176826
Delimiter is a - as shown. The elements are filename, number of clicks, date first clicked, date last clicked, numeric date first clicked, numeric date last clicked. I want to show the data in order from most to least popular.
Format of log.txt
111.42.32.44 - adsl-111-42-32-44.dsl.chcgil.ameritech.net - 2004-11-24 (21:09) - 1101352185 - filename.mp3 - 12887770 - http://www.website.com/filepage.php - Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
I am able to sort the log file in date order to show the latest file that was downloaded but I cannot sort the count file to display in terms of popularity. I have read the PHP manual on sort, file and a few other permutations until I am blind with fatigue. Here's the code. Any suggestions?
$count = file('count.txt');
$log = file('log.txt');
//loop through array putting each item into <td>
print "<table width='650' align='center'><tr><td><table width=100%><tr><td valign='top' height='121' width='112'><IMG SRC='/resources/tt1.gif' border='0'></td><td height='121' valign='middle' align='center'><H1><b><font face='verdana, arial, helvetica'>File Click Analyzer</H1></FONT></b><HR width=80%></td></tr></table></td></tr><tr><td> </td></tr><tr><td align='left'><font size='4' face='verdana, arial, helvetica' color='#CC0000'><b><A HREF='#file'>File Download Count</A></b></td></tr><tr><td><table width='600' class='ipf' align='center' cellspacing='0'><tr><td>File Clicked</td><td align='center'>Clicks</td><td>Last Downloaded</td><td>First Downloaded</td></tr><tr><td colspan='4' align='left'><HR width='95%'></td></tr>";
This produces a complete list but in the order that the file records were entered, first to last. I'm trying to get it by order of popularity, number of clicks.
foreach ($count as $line){
$data = explode(" - ", $line);
print "<tr style='cursor:default' onmouseover=style.backgroundColor='blue',style.color='white',style.fontWeight='bold' onmouseout=style.backgroundColor='transparent',style.color='black',style.fontWeight='normal'><td width=30%>$data[0]</td><td width=10% align='center'>$data[1]</td><td width=30%>$data[3]</td><td width=30%>$data[2]</td></tr>";
}
print"<A NAME='file'></A>";
print"</table></td></tr><tr><td> </td></tr><tr><td align='left'><font size='4' face='verdana, arial, helvetica' color='#CC0000'><b><A HREF='#user'>Downloader Info</A></b></td></tr><tr><td><table width='600' cellspacing='0' class='ipf' align='center'><tr><td>IP of Downloader</td><td>Date Downloaded</td><td>File Downloaded</td></tr><tr><td align='left' colspan='3'><HR width='95%'></td></tr>";
Everything from here down sorts by date just fine, displays correctly.
while (list ($key, $val) = each ($log)) {
list($IP, $IPaddr, $vdate, $adate, $fname, $unum, $wpag, $binf)=split(" - ", $val);
$newkey = substr($adate,3);
$new_ord[$newkey] = "$adate $IP $IPaddr $vdate $fname $unum $wpag $binf";
}
rsort($new_ord);
// foreach ($log as $line1){
// $data = explode(" - ", $line1);
while (list($key, $val) = each($new_ord)){
$line = explode( " ", $val );
print "<tr style='cursor:default' onmouseover=style.backgroundColor='blue',style.color='white',style.fontWeight='bold' onmouseout=style.backgroundColor='transparent',style.color='black',style.fontWeight='normal'><td width=30%>$line[1]</td><td width=30%>$line[3] $line[4]</td><td width=30%>$line[5]</td></tr>";
}
Thanks for looking people.
Tom