Jump to content

Union Query


doddsey_65

Recommended Posts

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

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.