ผมใช้วิธีที่ 2 ครับ
สร้าง temp_id (เป็นฟิลด์ที่กำหนดให้ต้องมีทุกตาราง)
เก็บค่าที่ไม่ซ้ำ หลังจากบันทึกเสร็จ ก็ใช้เป็นเงื่อนไขดึง auto id ออกมา
หรืออ้างอิง auto id เพื่อคำนวนเลขที่เอกสารต่อจากเอกสารก่อนหน้า
The value of mysql_insert_id() is affected only by statements issued within the current client connection. It is not affected by statements issued by other clients.