本文整理汇总了PHP中app\Comment::convertJson方法的典型用法代码示例。如果您正苦于以下问题:PHP Comment::convertJson方法的具体用法?PHP Comment::convertJson怎么用?PHP Comment::convertJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Comment
的用法示例。
在下文中一共展示了Comment::convertJson方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAllCommentsByBeverage
public static function getAllCommentsByBeverage($beverage_id)
{
$conn = mysqli_connect(getenv('DB_HOST'), getenv('DB_USERNAME'), getenv('DB_PASSWORD'), getenv('DB_DATABASE'));
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT beverage_comments.comment_id, beverage_comments.beverage_id, beverages.beverage_name, users.user_fname, beverage_comments.comment_descrip, beverage_comments.rating\n FROM beverage_comments\n LEFT JOIN users\n ON beverage_comments.user_id=users.user_id\n LEFT JOIN beverages\n ON beverage_comments.beverage_id=beverages.beverage_id\n WHERE beverage_comments.beverage_id=" . $beverage_id . ";";
$result = mysqli_query($conn, $sql);
$s = "[";
$numRows = mysqli_num_rows($result);
if ($numRows > 0) {
for ($i = 0; $i < $numRows; $i++) {
$row = mysqli_fetch_assoc($result);
$comment = new Comment($row["comment_id"], $row["beverage_id"], $row["beverage_name"], $row["user_fname"], $row["comment_descrip"], $row["rating"]);
$temp = $comment->convertJson();
$s .= $temp;
if ($i < $numRows - 1) {
$s .= ", ";
}
}
}
$s .= "]";
mysqli_close($conn);
return $s;
}