0
I have a table in the bank called toy, inside it I have the columns name, total, quantity available and amount donated. But I want to show only the name, total and total amount donated.
When I use the code below that I know is not what I have to use, brings me everything but I have repeated toy name on this table, and I wanted it to appear only once, and the total came with the highest value and the donated amount of that toy already added up.
if(isset($_REQUEST['rlanual']))
{
$ano1= $_REQUEST['rlanual'];
$res = $mysqli->query("select * from brinquedo where ano=$ano1");
$row1= $res->num_rows;
while($escrever = mysqli_fetch_array($res))
{
$nome1 = $escrever['nome'];
$total = $escrever['total'];
$qtd = $escrever['qtd_disponivel'];
echo "$nome1";
echo "$total";
echo "$qtd";
}
}
To take the greater value of the total I have it:
$sql1=$mysqli->query('SELECT MAX(total) FROM brinquedo');
$result1 = $sql1;
Summing up I don’t want the same toy to appear more than once. I’ve tried even string comparison and nothing.
Try using GROUP BY by the name of the toy right in your query.
– Matheus Marques
i tried using selectCount with group by but n was. always says q n can convert to string or int and i n know more q to do. so it brings me everything but as it has names repeated there not of the pq and the part of annual report.
– Kelly Cris
I created the table directly in the database and I’m using php pages to add values.
– Kelly Cris
but the table has the following columns: ID, NAME, TOTAL, QTD_DISPONIVEL, QTD_DOADO.
– Kelly Cris
Total is on the same table, when you get a new toy you update the total of all? I believe that total does not need to be in the table, since a sum can be made directly by query sql...
– h3nr1ke