0

i want to get the result of my count query in 2 table
my table :

    $userfans=mysql_query("select *from fans where id_userfans='$_SESSION[id_user]' and level='umum' limit 1");
    while($oinf=mysql_fetch_array($userfans)){
        $coinp=mysql_query("select * from fans_news where id_userf='$_SESSION[id_user]' and id_fans='$oinf[id_fans]' and status='Y'");
        $koinp=mysql_num_rows($coinp);
        while($oinp=mysql_fetch_array($coinp)){

        $comentar=mysql_query("select * from fans_comment,user where fans_comment.id_newsfans='$oinp[id_newsfans]'
        and fans_comment.id_usercf!='$_SESSION[id_user]' and fans_comment.id_usercf=user.id_user ");

    $comme=mysql_num_rows($comentar);   
    echo" ($comme) </br>";   

    }
    }

and the result :
(4)
(2)
(2)
(0)
(1)
(0)
(0)
(1)
(0)
(0)

but i want to calculate that count result. become -->10
anyone can help me
im so confuse..

4
Contributors
3
Replies
25
Views
3 Years
Discussion Span
Last Post by urtrivedi
1

You can use += which will add onto each previosu total through a loop

$koinp=mysql_num_rows($coinp);
$total = 0; // Put this is to define the variable and set the initial amount to 0
while($oinp=mysql_fetch_array($coinp)){



$comme=mysql_num_rows($comentar);   
   // echo" ($comme) </br>";
$total += $comme; // Add each value of $comme to the current $total

The outside your loop echo the $total

-1
I have the following table:

memberid  
2
2
3
4
3
...and I want the following result:

memberid    count
2           2
3           1    ---Edit by gbn: do you mean 2?
4           1
I was attempting to use:

  SELECT MemberID, 
         COUNT(MemberID) 
    FROM YourTable 
GROUP BY MemberID
...but now I want find which record which has maximum count. IE:
Votes + Comments
Start your own thread!
-1
SELECT MemberID, 
         COUNT(MemberID)  cnt
    FROM YourTable 
GROUP BY MemberID
order by cnt desc 
limit 0,1

Edited by urtrivedi

Votes + Comments
Don't answer someone else's question when they have hijacked a thread
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.