do you mean that after you have inserted 40 records, you want to remove the first record in the table each time a new record is entered, keeping the latets 40 entries?
ie $entries = "select count(field1) from table1"
to give you the number of entries
you would need to select the row that you want to delete
ie $value = "select field1 from table1 limit 1"
you can then just do a delete like
delete field1 from table1 where field1=$value limit 1
Is that of any help?