No I made that display sum total but from all city, I want to display from city that are in one common state.
For example:
You have table of cities that call table1, and you have table2 with group of another cities.
I wan to display total number of citizens form table1 and table2, but separated, not total sum from both.
I hope I did explain correctly...
$conn = mysqli_connect('localhost', 'root', '', 'test');
if (!mysqli_set_charset($conn, "utf8")) {
printf("Error loading character set utf8: %s\n", mysqli_error($conn));
}
$sql = "SELECT * FROM table1, table2";
$result = mysqli_query($conn, $sql);
function numCitizens($conn) {
$data = $conn->query("SELECT sum(citizens) as numCitizensFROM table2")->fetch_array();
return $data["numCitizens"];
}
$sum = numCitizens($conn);
while ($data = mysqli_fetch_array($result)) {
echo '<tr>';
echo '<th>'.$data['table1_id'].'</th>';
echo '<th>'.$data['table1_name'].'</th>';
echo '<th>'.$sum.'</th>';
echo '</tr>';
}
mysqli_close($conn);