How can I get the last entry in the last DATE field from a MySQL database using PHP?
The rows will not match the date, so I cannot just take the first or last row.
You want ORDER BY , and possibly LIMIT .
$query = 'SELECT * FROM `table` ORDER BY `date` DESC LIMIT 1';
SELECT * FROM [Table] ORDER BY [dateColumn] DESC
If you want only the first line:
In T-SQL:
SELECT TOP(1) * FROM [Table] ORDER BY [dateColumn] DESC
In MySQL:
SELECT * FROM `Table` ORDER BY `dateColumn` DESC LIMIT 1
LIMIT ORDER BY.
:
SELECT * FROM entries ORDER BY timestamp DESC LIMIT 1
, ? , , , . , ?
SELECT * FROM table ORDER BY recno DESC LIMIT 1;
SELECT * FROM table ORDER BY date_revised DESC LIMIT 1;
Thus, the PHP call will look like this:
$result = mysql_query("SELECT * FROM table ORDER BY date_revised DESC LIMIT 1");
- Nicholas
Source: https://habr.com/ru/post/1704511/More articles:Is there a better PureMVC alternative for flash projects? - flashWith ActiveRecord has_many through relationships, how do I remove associations when saving objects - ruby-on-railsHow to find the 3D coordinates of the projected rectangle? - geometryОтправить несколько дейтаграмм с помощью одного вызова send()? - socketsSQL Reporting Services 2005 - Как получить текущую дату как ReportParameter - sql-server-2005Delete only from memory not from database - ruby-on-railsIn Java defined by an object, is it possible to override one of the methods? - java.NET: How do I know if the encoding supports all characters in my string? - c #Grails UrlMappings with url ending in "/" - url-rewritingКакая папка по умолчанию создается в Microsoft Visual Basic? - vb.netAll Articles