$query = mysql_query("SELECT MAX(id) FROM contenidos"); $last_id = mysql_num_rows($query); echo $last_id;