Professor Zoom
Professor Zoom

Reputation: 349

Get MAX Date is not working in PHP

I would like to get the max date from table but when I do this in PHP, it doesn't show any results.

$max_date = mysql_query("SELECT MAX(periodo) FROM mytable") or die (mysql_error());
$max_date = mysql_fetch_assoc($max_date);
$max_date = $max_date['periodo'];

It's not displaying any errors just doesn't showing something, but when I do that query directly in PHPMyAdmin it works, I have no idea what I'm doing wrong

enter image description here

Upvotes: 0

Views: 122

Answers (1)

dlopez
dlopez

Reputation: 995

As @kamal pal said in his comment, you need to provide an alias for your column:

SELECT MAX(periodo) AS 'periodo' FROM mytable

Upvotes: 1

Related Questions