Jump to content

join query count


desithugg

Recommended Posts

[code]
$query = "SELECT forums.pic,forums.name,forums.des,forums.poster,forums.timer,forums.id,threads.fid FROM forums left join threads on threads.fid = forums.id  where category = 'general' ORDER BY ors ASC";
$result = mysql_query($query) or die(mysql_error());

[/code]

on the threads table i want to count how many threads are there that have the threads.fid = forums.id
do i use count i have tried count(threads.fid) and threads,count(fid) but didnt work. any other ideas?
Link to comment
https://forums.phpfreaks.com/topic/17425-join-query-count/
Share on other sites

try
[code]$query = "SELECT forums.pic,forums.name,forums.des,forums.poster,
forums.timer,forums.id, COUNT(threads.fid) as threadcount
FROM forums left join threads on threads.fid = forums.id 
where category = 'general'
ORDER BY ors ASC";[/code]
Link to comment
https://forums.phpfreaks.com/topic/17425-join-query-count/#findComment-74169
Share on other sites

Oops

[code]$query = "SELECT forums.pic,forums.name,forums.des,forums.poster,
forums.timer,forums.id, COUNT(threads.fid) as threadcount
FROM forums left join threads on threads.fid = forums.id 
where category = 'general'
GROUP BY forums.id
ORDER BY ors ASC";[/code]
Link to comment
https://forums.phpfreaks.com/topic/17425-join-query-count/#findComment-74173
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.