want2php Posted November 4, 2009 Share Posted November 4, 2009 hi, i have two tables: A.status (values below) stat statdef 1 online 2 offline 3 live B. log (values below) logid stat(get its data from A) time_date(timestamp) 1 1 2 1 3 2 4 1 .... and so on. What i want to achieve is to query the first table as a reference and then check and count table B for matching stat. I am a newbie to this and already spent hours but couldn't get the right result. here's my code: $sql = "select stat from status" while ($result = mysql_fetch_array) { $statsql = "select count(id) from log where stat = $result" $countstat = mysql_fetch_array($statsql); } echo ' Total number count'; echo 'online' . $countstat; echo 'offline' . $countstat; echo 'live' . $countstat; Link to comment https://forums.phpfreaks.com/topic/180244-help-with-outputting-data/ Share on other sites More sharing options...
sasa Posted November 4, 2009 Share Posted November 4, 2009 SELECT a.statdef, COUNT(b.logid) as cnt FROM status AS a LEFT JOIN log AS b ON a.stat=b.stat GROUP BY b.stat Link to comment https://forums.phpfreaks.com/topic/180244-help-with-outputting-data/#findComment-950891 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.