Table generation swap from SQL view to PHP query for cohort selection