To figure out how many classes have each type of unit (letters of the alphabet), I created an array called $units_array that consists of all the units and the used it in the following:
Code: Select all
foreach ($units_array as $unit) {
$result=mysqli_query($dbi, "SELECT COUNT(DISTINCT(class_id)) AS num FROM district_data WHERE user_type = 'student' AND class_id != '' AND class_units LIKE '%$unit%'");
if(mysqli_num_rows($result) > 0) {
$row=mysqli_fetch_array($result);
$count=$row['num'];
$rows.='
<tr>
<td>'.$unit.'</td>
<td>'.$count.'</td>
</tr>
';
}
}
Given all of this, I'm wondering if my query can be improved to significantly improve performance or if the structure of the DB is the primary culprit.