¿Cómo puedo ordenar por última fila de actualización?
Frecuentes
Visto 831 equipos
-1
I have one Sql Query to get all the informations from my table.
I created an list using an foreach.
And i want to order this list, by the last updated row.
Como este
$query - "SELECT * FROM table ORDER BY last_updated_row";
//call Query here
And when i updated a certain row, i want to put this row on the top of the list
I heard about time_stamp, can i use time_stamp for that?
¿Cómo puedo hacer eso?
Muchas Gracias
2 Respuestas
1
Assuming your using MySQL your table needs to be like this
CREATE TABLE table (
last_updated_row TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
That will give the row a create time stamp and update it on each update statement which effects the row
http://dev.mysql.com/doc/refman/5.0/en/timestamp-initialization.html
contestado el 28 de mayo de 14 a las 13:05
0
You can use just about any date/datetime/timestamp column in a table to sort by if needed. The only catch is you need to actually tienen it in the table.
Any of the above will allow sorts by ascending/descending order, but need to be maintained when inserting/updating a row.
Assuming you have the following structure:
table - someTable
id someVale updateTime
1 54634 ......
2 65138 ......
3 94141 ......
4 84351 ......
It doesn't matter what type of column updateTime
is - whether it is a date, a datetime, a timestamp, a simple order by updateTime
trabajará.
But you need to make sure that each insert/update you make to that row updates the column so that the sort will be true.
contestado el 28 de mayo de 14 a las 13:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas php or haz tu propia pregunta.