PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE timesheet ( id INT AUTO_INCREMENT PRIMARY KEY, time_in TIME, time_out TIME )
Copy Clear
Copy Format Clear
<?php $timeSheet = array( '10/20/2023 20:43', '10/21/2023 5:53', '10/23/2023 20:42', '10/24/2023 6:08', '10/24/2023 20:47', '10/25/2023 5:57', '10/25/2023 20:45', '10/26/2023 6:03', '10/26/2023 20:42', '10/27/2023 5:59', '10/27/2023 20:45', '10/28/2023 5:55', '10/30/2023 20:44', '10/31/2023 5:55', '10/31/2023 20:46', '11/1/2023 5:55', '11/1/2023 20:43', '11/2/2023 5:59', '11/2/2023 20:47', '11/3/2023 5:57', '11/3/2023 20:49', '11/4/2023 5:57', '11/6/2023 20:45', '11/7/2023 5:55', '11/7/2023 20:41', '11/8/2023 5:55', '11/8/2023 20:42', '11/9/2023 5:55', '11/9/2023 20:42', '11/10/2023 5:55', '11/10/2023 20:46', '11/11/2023 5:53' ); $query = "INSERT INTO timesheet (time_in, time_out) VALUES "; foreach (array_chunk($timeSheet, 2) as $chunk) { $timeIn = $chunk[0]; $timeOut = $chunk[1]; $query .= "('$timeIn', '$timeOut'),"; } $query = rtrim($query, ","); if ($mysqli->query($query) == TRUE) { echo "Records inserted successfully"; } else { echo "Error: " . $query . "<br>" . $mysqli->error; }
Show:  
Copy Clear