Hey all,
I'm having a problem with an SQL query. I'm writing some banner exchange scripts, and in the client area I want to show the top 5 referer sites.
Now, the problem is I'm not 100% sure how to do this. I read the MySQL manual and came up with:
$query = "SELECT referer, bannerid, COUNT(*) FROM bannerclick WHERE bannerid='$user_id' GROUP BY referal, bannerid";
'referer' is the referer variable stored when somebody clicks on a banner. 'bannerid' is an id corresponding to the account the banner belongs to. '$user_id' is the account id of the person currently looking at the page (so I only got the referers for his account).
According to the MySQL manual, this should return each referer with the amount of bannerid (= the number of click throughs) in the table.
Then I try to use:
sort($row, SORT_NUMERIC)
and then echo the first 5 rows. The problem is I'm not sure how the Query results will be stored in $row.
Does (After sort) $row[0]["referer"] contain the referer with the most clicks? This doesn't seem like the best way to do it, so any input is appreciated. Thanks in advance