doddsey_65 Posted September 16, 2011 Share Posted September 16, 2011 The following union query is supposed to return the total number of alerts and the total number of messages, however a dump of the returned array shows only the alerts(num_alerts). $sql = "SELECT COUNT(a.a_aid) as num_alerts FROM ".Asf_Db::$prefix."alerts a UNION SELECT COUNT(m.m_mid) as num_messages FROM ".Asf_Db::$prefix."messages m"; $sth = Asf_Core::$db->prepare($sql); $sth->execute() or die(Asf_Core::$db->error($sth, $sql)); $results = $sth->fetch(PDO::FETCH_ASSOC); dump($results); anyone see where im going wrong? Link to comment https://forums.phpfreaks.com/topic/247249-union-query/ Share on other sites More sharing options...
web_craftsman Posted September 16, 2011 Share Posted September 16, 2011 COUNT(*) Link to comment https://forums.phpfreaks.com/topic/247249-union-query/#findComment-1269803 Share on other sites More sharing options...
web_craftsman Posted September 16, 2011 Share Posted September 16, 2011 ups, have not read correctly. You need fetch second record also $result1 = $sth->fetch(PDO::FETCH_ASSOC); $result2 = $sth->fetch(PDO::FETCH_ASSOC); Link to comment https://forums.phpfreaks.com/topic/247249-union-query/#findComment-1269804 Share on other sites More sharing options...
doddsey_65 Posted September 16, 2011 Author Share Posted September 16, 2011 erm....no. result1 would be the same as result 2 since its returning the same query Link to comment https://forums.phpfreaks.com/topic/247249-union-query/#findComment-1269805 Share on other sites More sharing options...
web_craftsman Posted September 16, 2011 Share Posted September 16, 2011 what returns print $sth->rowCount(); ? Link to comment https://forums.phpfreaks.com/topic/247249-union-query/#findComment-1269808 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.