problem in using while loop in php&mysql

Posted by Mac Taylor on Stack Overflow See other posts from Stack Overflow or by Mac Taylor
Published on 2010-05-29T09:58:39Z Indexed on 2010/05/29 10:02 UTC
Read the original article Hit count: 171

Filed under:
|

hey guys

im using a while loop to show my latest forum topics

now i need to count some fields either

I'm trying to do it in one query and here is my code :

$result = $db->sql_query("SELECT t.*,p.*,
   SUM(t.topic_approved='1') AS Amount_Of_Topics,
   SUM(t.topic_views) AS Amount_Of_Topic_Views,
   SUM(t.topic_replies) AS Amount_Of_Topic_Replies, 
   SUM(p.post_approved ='1') AS Amount_Of_Posts
FROM  bb3topics t left join  bb3posts p ON t.topic_id=p.topic_id
ORDER BY t.topic_last_post_id DESC LIMIT 10
"
);


while( $row = $db->sql_fetchrow($result) )
{

problem :

this code shows only one forum topic and not the rest , but if i remove sum() part from it , then it shows the rest

is there anything wrong with my query code ?!

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql