3
I need to get several variables based on my bank to mount a full Dashboard. For example, I need the number of lines, the average value of a given field and the same average value only per FU.
The strategy that has worked with me is to ask for access through the function msqli_connect()
and right after the request answered I close with msqli_close()
. With this I’m only getting one action, IE, only the average, or only the list of all users, or just the sum. I couldn’t, for example, get the average and the sum within the same request. Is that right? how can I request more data in the same request?
The code I’ve been using is:
// Para conseguir a média
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT AVG(q1) AS avg FROM nome_da_tabela";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo $row["avg"];
}
} else {
echo "0 results";
}
mysqli_close($conn);
// agora para conseguir a soma:
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT SUM(q1) AS soma FROM nome_da_tabela";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo $row["soma"];
}
} else {
echo "0 results";
}
mysqli_close($conn);
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site
– Maniero