public static function showMessages() { $db = Db::getConnection(); $query = 'SELECT * FROM messages'; $result = $db->prepare($query); $result->execute(); $row = $result->rowCount(); if ($row) { $arrayOfChunk = array(); $query = 'SELECT * FROM messages JOIN users ON users.user_id=messages.user_id ORDER BY message_date'; $result = $db->prepare($query); $result->execute(); $rows = $result->rowCount(); for ($j = 0; $j < $rows; $j++) { $chunkRow = $result->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT, $j); $chunkRow['user_message'] = stripslashes($chunkRow['user_message']); if ($chunkRow['is_visible']) { $arrayOfChunk[] = $chunkRow; } else { continue; } } return $arrayOfChunk; } return false; }
/** * Метод, получающий int $limit последних новостей * @param int $limit * @return mixed object News */ public static function getThreeLastRecord(int $limit) { $sql = 'SELECT * FROM ' . static::TABLE . ' ORDER BY id DESC LIMIT ' . $limit; $db = Db::instance(); return $db->query($sql, static::class); }
public static function fetchCities() { $db = Db::getConnection(); $arrayOfCities = array(); $query = "SELECT * FROM cities WHERE region_id='" . $_GET['region_id'] . "'"; $result = $db->prepare($query); $result->execute(); $rows = $result->rowCount(); for ($j = 0; $j < $rows; $j++) { $chunkRow = $result->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT, $j); $arrayOfCities[] = $chunkRow; } print_r(json_encode($arrayOfCities)); }