public static function getRange($start_date, $end_date) { $mysqli = new mysqli("localhost", "root", "password", "426project"); $query = "SELECT id FROM entries WHERE created_at >= '{$start_date}' AND created_at <= '{$end_date}' ORDER BY created_at"; console_log($query); $result = $mysqli->query($query); $entries = array(); if ($result) { for ($i = 1; $i < $start; $i++) { $result->fetch_row(); } for ($i = $start; $i <= $end; $i++) { $next_row = $result->fetch_row(); if ($next_row) { $entries[] = Entry::findByID($next_row[0]); } } } return $entries; }
// console_log(Entry::getRange($new_start_date->format('Y-m-d'), $new_end_date->format('Y-m-d'))); print json_encode(Entry::getRange($new_start_date->format('Y-m-d'), $new_end_date->format('Y-m-d'))); exit; } // ID not specified, then must be asking for index header("Content-type: application/json"); print json_encode(Entry::getAllIDs()); exit; } else { if ($_SERVER['REQUEST_METHOD'] == "POST") { // Either creating or updating // Following matches /entry.php/<id> form if (count($path_components) >= 2 && $path_components[1] != "") { //Interpret <id> as integer and look up via ORM $entry_id = intval($path_components[1]); $entry = Entry::findByID($entry_idy); if ($entry == null) { // Entry not found. header("HTTP/1.0 404 Not Found"); print "Entry id: " . $entry_id . " not found while attempting update."; exit; } // Validate values $new_author_id = false; if (isset($_REQUEST['author_id'])) { $new_author_id = trim($_REQUEST['author_id']); if ($new_author_id == 0) { header("HTTP/1.0 400 Bad Request"); print "Can't save an entry without an author! (Please log in or register)"; exit; }