PHP MySQL combine multiple fetchcolumn into a single query -


i've got table users , variable user status (1, 2, 3, 4, 5 etc). calculating number of users in each status separately

$query = "select count(*) users status = 1"; $result = $pdo->query($query); $users1 = $result->fetchcolumn();  $query = "select count(*) users status = 2"; $result = $pdo->query($query); $users2 = $result->fetchcolumn();  etc 

i fetch, loop through results , add each status wondering if there better way query?

you can use group , list count

select status, count(*)  my_count users group status; 

nb can't use fetchcolumn .. fetchrow .and access key


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -