Hello. The question may be banal but I have not yet found a solution. I select from the database what I need:

$sql = "SELECT * FROM `members`"; $result = $db->query($sql); while($row = mysqli_fetch_array($result)) { $balans = $row['balans']; $email = $row['email']; $username =$row['username']; echo "Баланс: $row[balans]. Юзер: $row[username]. Почта: $row[email].<br>"; } 

But still it would be desirable to sum up we admit balance and users and to bring out echo.

 SELECT COUNT(*) FROM `members`"; 

As a question to implement and whether it is permissible on one page several $ sql queries in this case. thank

  • What do you mean by the phrase sum up users? - Artem Polikarpov

2 answers 2

The amount and number of users can be calculated directly in the script:

 $sql = "SELECT * FROM `members`"; $result = $db->query($sql); $sum = 0; $count = 0; while($row = mysqli_fetch_array($result)) { $balans = $row['balans']; $email = $row['email']; $username =$row['username']; $sum += $row['balans']; $count++; echo "Баланс: $row[balans]. Юзер: $row[username]. Почта: $row[email].<br>"; } echo "Всего пользователей: " . $count . "<br>"; echo "Общая сумма: " . $sum . "<br>"; 

In general, requests on one page can be as much as you need. Although 1000. But each request increases the execution time of the script.

  • Thanks It works. - Join Jexon
  • @JoinJexon, on this site, instead of thanks, take the answer as an answer to your question and put +1) - Yuriy Prokopets Sep.
 SELECT COUNT(*) as count_members, SUM(balans) as total_balans FROM `members`