0
The table has two columns, one of user data and another of user points, the user points works like the bank statement scheme, but need to return only the last value, and I did so
SELECT `usuario`.*, `pontos`.`ponto_valor` FROM `usuario` INNER JOIN `pontos` ON `pontos`.`ponto_id_user` = `usuario`.`user_id` ORDER BY `usuario`.`data_cad` DESC, `pontos`.`data_cad` DESC;
And I did a while with PHP for that:
<?php
$instrucaoSQL = "SELECT
`usuario`.*,
`pontos`.`ponto_valor`
FROM
`usuario`
INNER JOIN
`pontos`
ON
`pontos`.`ponto_id_user` = `usuario`.`user_id`
ORDER BY
`usuario`.`data_cad`
DESC,
`pontos`.`data_cad`
DESC;";
$instrucaoQuery = mysqli_query($conn, $instrucaoSQL);
$contaQuery = mysqli_num_rows($instrucaoQuery);
if($contaQuery > 0) {
while ( $r = mysqli_fetch_array($instrucaoQuery) ) {
echo $r['user_nome'] . " - " . $r['ponto_valor'] . "<br>";
}
?>
However the result comes all duplicated, I would like only the last value (row) of the table 'points' to be displayed, without duplicating the names of the table 'user' every time I find a related value in the table 'points'.
That $r is what?
– Lucas de Carvalho
is array, which receives database results, but solved, thanks.
– ElvisP