SELECT MAX(fieldname) FROM tablename;

will get you the maximum id in the table.

What code do you have so far, though?