Jeg er ikke sikker på jeg forstår hvad du mener med:
WHERE forumthreads.x = forumcomments.y category='".$row_forum_categories['id']."'");
Jeg har nu umiddelbart prøvet med:
$forum_count_threads = mysql_query("SELECT COUNT(forumthreads.id), COUNT(forumcomments.id) FROM forumthreads LEFT JOIN forumcomments ON forumthreads.category = forumcomments.category_id WHERE category='".$row_forum_categories['id']."'");
men den returnere også forkerte resultater..
Er det bedst blot at lave mine to counts i to forskellige queries idet der er fra forskellige tabeller?
Beklager ventetiden, og mange tak for din tålmodighed med mig :)
Jeg har fået fremstykket mig frem til flg. $forum_count_threads = mysql_query("SELECT COUNT(forumthreads.id) AS total_threads, COUNT(forumcomments.thread_id) AS total_comments FROM forumthreads, forumcomments WHERE forumthreads.id = forumcomments.thread_id AND forumthreads.category='".$row_forum_categories['id']."'");
Jeg synes jeg har prøvet alle tænklige kombinationer, men den returnere stadig ikke korrekte tal.
total_comments returneres korrekt, desværre returnere den samme værdi som total_comments har i total_threads-
Ah. Ja - der er altid lige mange raekker i alle kolonner i query output.
Men der er et lile trick !
$forum_count_threads = mysql_query("SELECT COUNT(forumthreads.id) AS total_threads, COUNT(DISTINCT forumcomments.thread_id) AS total_comments FROM forumthreads, forumcomments WHERE forumthreads.id = forumcomments.thread_id AND forumthreads.category='".$row_forum_categories['id']."'");
$forum_count_threads = mysql_query("SELECT COUNT(DISTINCT forumthreads.id) AS total_threads, COUNT(forumcomments.thread_id) AS total_comments FROM forumthreads, forumcomments WHERE forumthreads.id = forumcomments.thread_id AND forumthreads.category='".$row_forum_categories['id']."'");
$forum_count_threads = mysql_query("SELECT COUNT(DISTINCT forumthreads.id) AS total_threads, COUNT(forumcomments.id) AS total_comments FROM forumthreads, forumcomments WHERE forumthreads.id = forumcomments.thread_id AND forumthreads.category='".$row_forum_categories['id']."'");
$forum_count_threads = mysql_query("SELECT COUNT(DISTINCT forumthreads.id) AS total_threads, COUNT(forumcomments.thread_id) AS total_comments FROM forumthreads LEFT JOIN forumcomments ON forumthreads.id = forumcomments.thread_id WHERE forumthreads.category='".$row_forum_categories['id']."'");
- Did the trick :)
Jeg vil takke af for i aften, mange tak for hjælpen- det har været kanon.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.