public function loadTweets() { $conn = $this->connection; $sqlQuery = "SELECT user_id, tweets.id, text FROM tweets INNER JOIN users ON tweets.user_id = users.id ORDER BY tweets.created_at DESC"; $result = $conn->query($sqlQuery); if ($result->num_rows > 0) { while (list($userId, $tweetId, $text) = $result->fetch_array(MYSQLI_NUM)) { $tweet = new Tweet($conn); $tweet->setUserId($userId); $tweet->setText($text); $tweet->setId($tweetId); $this->arrayWithTweets[] = $tweet; } return true; } else { return false; } }
<?php session_start(); require_once '../resources/require.php'; // Dodaje nowy wpis do bazy, uzupełnia komunikat o dodaniu bądź błędach. if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (trim($_POST['text']) != '') { $tweet = new Tweet($mysqli); $tweet->setUserId($_SESSION['user_id']); $tweet->setText($_POST['text']); if (!$tweet->create()) { $info = 'Błąd przy dodawaniu wpisu'; } else { $info = 'Dodano nowy wpis'; } } else { $info = 'Uzupełnij treść wpisu!'; } } ?> <!DOCTYPE html> <html lang="pl-PL"> <title>Twitter | Strona główna</title> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> </head> <body>
<?php include_once "../configRoot.php"; require_once ROOT_NAME . "/classes/Database.php"; require_once ROOT_NAME . "/classes/Tweet.php"; require_once ROOT_NAME . "/includes/checkProfile.php"; if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["tweet"])) { $text = $_POST["tweet"]; $text = htmlspecialchars($text); $db = Database::getInstance(); $conn = $db->getConnection(); $tweet = new Tweet($conn); $tweet->setUserId($id); $tweet->setText($text); $tweet->create(); header("location: ../index.php"); } else { header("location: ../index.php"); }