assign last field of a table to an input text

Asked

Viewed 20 times

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 else select max(campo_id) from tabela

  • Assuming there is an auto-increment id it can be like this select * from tabela&#xA;where id = (select max(id) from tabela)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.