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
$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];
}
$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 />";
}
?>