echo "COLDEF|".json_encode(DB::select("SHOW COLUMNS FROM questions WHERE Field = 'status_id'"))."\n"; try { foreach (DB::table('statuses')->get() as $s) echo "STATUS|".json_encode($s)."\n"; } catch (\Exception $e) { echo "no statuses table: ".$e->getMessage()."\n"; } foreach (DB::table('questions')->select('status_id', DB::raw('count(*) c'))->groupBy('status_id')->orderByDesc('c')->get() as $r) echo "QCOUNT|status_id=".var_export($r->status_id,true)."|".$r->c."\n";