0
I have a chart that stores a vehicle’s supplies and would like to make the following code work. I need to take the last record with the odometer mileage and already bring the specific input text, called kmAnterior. It has to be the last field, for me to find out the way. Example: kmAnterior 115, kmAtual 215. Calculation (kmAtual - kmAnterior) = 100 km. Then the current one I will type, and I would like the previous one to automatically search in the table (last record saved). I’m doing it in a way that’s not working:
<input type="text" name = "kmAnterior" placeholder = "KM Anterior" value = "<?php echo $linha['kmAbastecimento']; ?>">
Where that $linha
is the way I’m using to fill a table (using while). I want to be able to always take the last value of the table and launch directly in this field, in a cleaner and simpler way possible, because the table has a number of other calculations.
What table structure? How is your SELECT? At first this can solve
SELECT * FROM [TABELA] ORDER BY [CAMPO] DESC LIMIT 1
or elseselect max(campo_id) from tabela
– user60252
Assuming there is an auto-increment id it can be like this
select * from tabela
where id = (select max(id) from tabela)
– user60252