how to show top reffere user from mysql...???

Started on the old forum in September 2010 · view the original in the archive · old links redirect here

4 replies · 742 views · started 16 years ago · 1 min read

3 participants
slowy Senior · 357 posts #1

hi, guys i want to show the top 5 refferer user from my sql table. table has following thing. database name- users total table-3 table name-id,ref,name here: id=user id ref=the user id of that user who is reffered this user name=username

following is the entry in above 3 tables 1,0,abc 2,1,def 3,1,ghi 4,2,jkl 5,1,mno 6,2,pqr 7,1,stv 8,5,uwx 9,8,xyz 10,8,aaa

according to above table i want to show this abc=4 def=2 uwx=2 mno=1

plz help in dis

something else Fellow · 2,296 posts #2

something on the lines of:

$sql = mysql_query"SELECT name, COUNT(ref) AS NumOccurrences FROM users GROUP BY ref HAVING (COUNT(ref)>0)");
while($list = mysql_fetch_array($sql)){
echo $list[0].'='.$list[1];
}
slowy Senior · 357 posts #3

something else wrote: something on the lines of:

$sql = mysql_query"SELECT name, COUNT(ref) AS NumOccurrences FROM users GROUP BY ref HAVING (COUNT(ref)>0)");
while($list = mysql_fetch_array($sql)){
echo $list[0].'='.$list[1];
}

i putted dis

<?php 
include ("header.php");
$sql = mysql_query'SELECT 'name',COUNT(ref) AS NumOccurrences FROM 'users' GROUP BY 'ref' HAVING (COUNT(ref)>0)';
while($list = mysql_fetch_array($sql)){
echo $list[0].'='.$list[1];
}
?>

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/abc/public_html/aaaa.php on line 3

after that i putted

<?php 
include ("header.php");
$sql = "SELECT name, COUNT(ref) AS NumOccurref FROM users GROUP BY ref HAVING (COUNT(ref)>0)";
while($list = mysql_fetch_array($sql)){
echo $list[0].'='.$list[1];
}
?>

but Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/abc/public_html/aaaa.php on line 4

Added after 33 minutes:

now i putted dis,every thing is fine but not giving data what i want

<?php 
include ("header.php");
$sql = "SELECT name, COUNT(ref) AS NumOccurrences FROM users GROUP BY ref HAVING (COUNT(ref)>0) LIMIT 0, 5;";
$sites=MySQL_Query($sql);
while($list = mysql_fetch_array($sites))
{
echo $list[0].'='.$list[1];
echo "<br />";
}
?>
something else Fellow · 2,296 posts #4

if the last 1 is working just get rid of the limit 0, 5; as u will be only displaying 5 results

Vayne Developer · 106 posts #5

SELECT field FROM table ORDER BY field DESC and put it on while loop.

Nous Ne Dansos Pas, Nous Sommes Le Danse.!

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close