ทำได้โดยการ ใช้ foreach วน loop ให้จนหมด
โดย $res_items_track เก็บค่า array อยู่
ซึ่งในตัวอย่าง ข้างใน $res_items_track ประกอบด้วยข้อมูล barcode status location postcode status_description delivery_description
ชุดข้อมูล array
โค้ด: เลือกทั้งหมด
[0] => Array
(
[barcode] => EF582568151TH
[status] => 103
[status_description] => รับฝาก
[status_date] => 24/07/2562 09:04:05+07:00
[location] => สำเหร่
[postcode] => 10600
[delivery_status] =>
[delivery_description] =>
[delivery_datetime] =>
[receiver_name] =>
[signature] =>
)
[1] => Array
(
[barcode] => EF582568151TH
[status] => 201
[status_description] => อยู่ระหว่างการขนส่ง
[status_date] => 24/07/2562 11:02:43+07:00
[location] => สำเหร่
[postcode] => 10600
[delivery_status] =>
[delivery_description] =>
[delivery_datetime] =>
[receiver_name] =>
[signature] =>
)
[2] => Array
(
[barcode] => EF582568151TH
[status] => 206
[status_description] => ถึงที่ทำการไปรษณีย์
[status_date] => 24/07/2562 14:55:43+07:00
[location] => หลักสี่
[postcode] => 10210
[delivery_status] =>
[delivery_description] =>
[delivery_datetime] =>
[receiver_name] =>
[signature] =>
)
[3] => Array
(
[barcode] => EF582568151TH
[0] => Arr [location] => สำเหร่
[postcode] => 10600
[delivery_status] =>
[delivery_description] =>
[delivery_datetime] =>
[receiver_name] =>
[signature] =>
)
[1] => Array
(
[barcode] => EF582568151TH
[status] => 201
[status_description] => อยู่ระหว่างการขนส่ง
[status_date] => 24/07/2562 11:02:43+07:00
[location] => สำเหร่
[postcode] => 10600
[delivery_status] =>
[delivery_description] =>
[delivery_datetime] =>
[receiver_name] =>
[signature] =>
)
[2] => Array
(
[barcode] => EF582568151TH
[status] => 206
[status_description] => ถึงที่ทำการไปรษณีย์
[status_date] => 24/07/2562 14:55:43+07:00
[location] => หลักสี่
[postcode] => 10210
[delivery_status] =>
[delivery_description] =>
[delivery_datetime] =>
[receiver_name] =>
[status] => 201
[status_description] => อยู่ระหว่างการขนส่ง
[status_date] => 24/07/2562 14:58:58+07:00
[location] => หลักสี่
[postcode] => 10210
[delivery_status] =>
[delivery_description] =>
[delivery_datetime] =>
[receiver_name] =>
[signature] =>
)
[4] => Array
(
[barcode] => EF582568151TH
[status] => 301
[status_description] => อยู่ระหว่างการนำจ่าย
[status_date] => 24/07/2562 15:14:22+07:00
[location] => สำนักงาน ปณท.
[postcode] => 10002
[delivery_status] =>
[delivery_description] =>
[delivery_datetime] =>
[receiver_name] =>
[signature] =>
)
[5] => Array
(
[barcode] => EF582568151TH
[status] => 501
[status_description] => นำจ่ายสำเร็จ
[status_date] => 24/07/2562 16:59:59+07:00
[location] => สำนักงาน ปณท.
[postcode] => 10002
[delivery_status] => S
[delivery_description] => ผู้รับได้รับสิ่งของเรียบร้อยแล้ว
[delivery_datetime] => 24/07/2562 16:59:59+07:00
[receiver_name] => รอจ่าย
[signature] => https://track.thailandpost.co.th/signature/QDY4MTUxYjVzMGx1VDMz/QGI1c0VGMGx1VDMx/QGI1czBsVEh1VDM0/QGI1czBsdTU4MjVUMzI=
)
[6] => Array
(
[barcode] => EF582568151TH
[status] => 301
[status_description] => อยู่ระหว่างการนำจ่าย
[status_date] => 26/10/2562 09:50:42+07:00
[location] => ร้องกวาง
[postcode] => 54140
[delivery_status] =>
[delivery_description] =>
[delivery_datetime] =>
[receiver_name] =>
[signature] =>
)
[7] => Array
(
[barcode] => EF582568151TH
[status] => 501
[status_description] => นำจ่ายสำเร็จ
[status_date] => 26/10/2562 10:00:44+07:00
[location] => ร้องกวาง
[postcode] => 54140
[delivery_status] => S
[delivery_description] => ผู้รับได้รับสิ่งของเรียบร้อยแล้ว
[delivery_datetime] => 26/10/2562 10:00:44+07:00
[receiver_name] => ยุพิน/ภรรยา
[signature] => https://track.thailandpost.co.th/signature/QDY4MTUxYjVzMGx1VDMz/QGI1c0VGMGx1VDMx/QGI1czBsVEh1VDM0/QGI1czBsdTU4MjVUMzI=
)
โค้ด: เลือกทั้งหมด
foreach ($res_items_track as $key => $value) {
$barcode = $value['barcode'];
$status =$value['status'];
$location = $value['location'];
$postcode = $value['postcode'];
$status_description = $value['status_description'];
$delivery_description = $value['delivery_description'];
$sql = "INSERT INTO data_tracking (barcode,status,location,status_description,delivery_description)
VALUES ('$barcode','$status','$location','$status_description','$delivery_description')";
mysqli_query($con, $sql) or die(mysqli_error($con));
}
barcode คือ เลขพัสดุ
status คือ สถานะของพัสดุ
location คือ สถานที่ ที่พัสดุถึง
postcode คือ รหัสไปรษณีย์ที่พัสดุถึง
status_description คือ รายละเอียดของพัสดุ เช่น จัดส่งเรียบร้อยแล้ว
delivery_description คือ รายละอียดเมื่อพัสดุส่งถึงปลายทาง