First of all, what is your native language? Is English your primary language? I am in no way trying to make sarcastic remarks or offend your nationality; I merely wondered if you're English was a bit confusing simply because it is not your primary language. If it is, however, I would suggest proofreading your posts!
Are you saying you have the column 'total' in your SQL table? If not, why not add that, so that each time the script adds a row for 'a', you could have a "totals" table that would be updated each time?
At any rate, I'm a bit rusty on SQL, and I don't know that I understand you entirely, but I believe I could solve your problem by doing something like this:
$query = "SELECT COUNT(rid) AS total, name, rid FROM referrer GROUP BY name ORDER BY rid DESC LIMIT 5";
$exec = mysql_query($query) or die('Error, MySQL said: ' . mysql_error());
$i = 0;
while($result = mysql_fetch_assoc($exec)) {
echo 'Referer #' . $i . ': ' . $result['name'] . ' has ' . $result['total'] . ' hits.<br>';
$i++;
}
I BELIEVE this is what you are asking for. It will count how many times a 'name' is repeated (returned as the 'total' column) and order the results by 'rid'. The output would be something like:
Referrer #1: a has 6 hits.
Referrer #2: b has 5 hits.
Referrer #3: c has 4 hits.
Referrer #4: d has 3 hits.
Referrer #5: e has 2 hits.