php - can i merge those 2 queries in one query -


hello can merge 2 queries in 1 query first query number of articles in database , second query sum of visits of article whats best method make 1 query

$stmt = $db->query('select * stories'); $story_count = $stmt->rowcount();  $stmt = $db->query("select sum(visits) stories"); $total_visits = $stmt->fetchcolumn(); 

try like

$stmt = $db->query('select count(*) total_cnt,                    sum(visits) total_visits stories'); 

then excute query,you result "total_cnt" , "total_visits"


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -