I'm trying to count/group by for 25 columns in a table. I have success counting one column at a time using ...
//COUNT OFF
$sql = "SELECT count(q1) as count, q1 FROM results GROUP BY q1";
$stmt = $db->prepare($sql);
$stmt->execute();
$firstResults = $stmt->fetchAll();
$sql = "SELECT count(q2) as count, q2 FROM results GROUP BY q2";
$stmt = $db->prepare($sql);
$stmt->execute();
$secondResults = $stmt->fetchAll();
$sql = "SELECT count(q3) as count, q3 FROM results GROUP BY q3";
$stmt = $db->prepare($sql);
$stmt->execute();
$thirdResults = $stmt->fetchAll();
$firstResults = json_encode($firstResults);
$secondResults = json_encode($secondResults);
$thirdResults = json_encode($thirdResults);
..and that works fine for a few columns. It seems like there should be a less-repetitive way to do the same for 25 columns in the same table. Where would I start?