本文整理汇总了PHP中Tweet::setUserId方法的典型用法代码示例。如果您正苦于以下问题:PHP Tweet::setUserId方法的具体用法?PHP Tweet::setUserId怎么用?PHP Tweet::setUserId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tweet
的用法示例。
在下文中一共展示了Tweet::setUserId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadTweets
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;
}
}
示例2: Tweet
<?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>
示例3: htmlspecialchars
<?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");
}