codice:
SELECT MAX(id) as massimo FROM tabella
dopo il fetch ce l'hai in $mydata = $row["massimo"];