Jump to content

_fr99rf_

New Members
  • Content Count

    4
  • Joined

  • Last visited

Everything posted by _fr99rf_

  1. Well, thank you Max, I will give a try and let you know If I am on the right way... Thanks, and enjoy your second coffee
  2. 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);
  3. Hi Barand, thanks for your quick reply. If I did understand correctly, there is foreign key with relation between. Maybe my question is not set up correctly.. I want make query with "SELECT" to 2 different tables? Thanks!
  4. Hi everyone, I'm having troubles with query from database. I want to select all from one table and select sum from second table in the same time. Is this possible? Here is my script: $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 first_id, first_name FROM first"; $sql = "SELECT sum(total) as SumTotal FROM second"; $result = mysqli_query($conn, $sql); while ($data = mysqli_fetch_array($result)) { echo '<tr>'; echo '<th>'.$data['first_id'].'</th>'; echo '<th>'.$data['first_name'].'</th>'; echo '<th>'.$data['SumTotal'].'</th>'; echo '</tr>'; } mysqli_close($conn); Thanks!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.