Currently my code is like this:
<?php
$qall = $db->query("SELECT * FROM location_code
WHERE
StateCode='".$secureStateCode."'");
while($fall = $db->fetch($qall)) {
?>
<tr>
<th><?php echo $fall['StateCode']; ?></th>
<td><?php echo $fall['StateName']; ?></td>
<td>
<?php
$query = $db->query("SELECT COUNT(*) AS `male_count`
FROM `all_users`
WHERE `Sex`='M'
AND
`StateCode`='{$fall['StateCode']}'");
$data = $db->fetch($query);
echo $data['male_count'];
?>
</td>
<td>
<?php
$query = $db->query("SELECT COUNT(*) AS `female_count`
FROM `all_users`
WHERE `Sex`='F'
AND
`StateCode`='{$fall['StateCode']}'");
$data = $db->fetch($query);
echo $data['female_count'];
?>
</td>
<td>Total male_count + female_count</td>
</tr>
<?php } ?>
How do I combine these queries and get them loading faster for the total of male & female. Currently I have about 500k users.
Should return three rows, like so:
You should be able to get the rest from there =)