本文整理汇总了PHP中post::from_array方法的典型用法代码示例。如果您正苦于以下问题:PHP post::from_array方法的具体用法?PHP post::from_array怎么用?PHP post::from_array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类post
的用法示例。
在下文中一共展示了post::from_array方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* Load post from database. Returns false, if the post doesn't exist
* @param int $post_id
* @return boolean|Gn36\OoPostingApi\post
*/
static function get($post_id)
{
global $db;
$sql = "SELECT * FROM " . POSTS_TABLE . " WHERE post_id=" . intval($post_id);
$result = $db->sql_query($sql);
$post_data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$post_data) {
//post does not exist, return false
return false;
}
return post::from_array($post_data);
}
示例2: get
/** static method, loads the post with a given post_id from database.
* returns false if the post does not exist */
static function get($post_id)
{
global $db;
//$sql = "SELECT p.*, t.topic_first_post_id, t.topic_last_post_id
// FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t
// WHERE p.post_id=" . intval($this->post_id) . " AND t.topic_id = p.topic_id";
$sql = "SELECT * FROM " . POSTS_TABLE . " WHERE post_id=" . intval($post_id);
$result = $db->sql_query($sql);
$post_data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$post_data) {
//post does not exist, return false
return false;
}
return post::from_array($post_data);
}
示例3: get
/**
* Load topic from database
*
* @param int $topic_id
* @param boolean $load_posts Whether to load the posts as well
* @return boolean|\Gn36\OoPostingApi\topic
*/
static function get($topic_id, $load_posts = false)
{
global $db;
$sql = "SELECT * FROM " . TOPICS_TABLE . " WHERE topic_id=" . intval($topic_id);
$result = $db->sql_query($sql);
$topic_data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$topic_data) {
// topic does not exist, return false
return false;
}
// create object and fill in data
$topic = new topic();
$topic->topic_id = $topic_data['topic_id'];
$topic->forum_id = $topic_data['forum_id'];
$topic->icon_id = $topic_data['icon_id'];
$topic->topic_attachment = $topic_data['topic_attachment'];
$topic->topic_reported = $topic_data['topic_reported'];
$topic->topic_views = $topic_data['topic_views'];
$topic->topic_visibility = $topic_data['topic_visibility'];
$topic->topic_posts_approved = $topic_data['topic_posts_approved'];
$topic->topic_posts_unapproved = $topic_data['topic_posts_unapproved'];
$topic->topic_posts_softdeleted = $topic_data['topic_posts_softdeleted'];
$topic->topic_delete_time = $topic_data['topic_delete_time'];
$topic->topic_delete_reason = $topic_data['topic_delete_reason'];
$topic->topic_delete_user = $topic_data['topic_delete_user'];
$topic->topic_status = $topic_data['topic_status'];
$topic->topic_moved_id = $topic_data['topic_moved_id'];
$topic->topic_type = $topic_data['topic_type'];
$topic->topic_time_limit = $topic_data['topic_time_limit'];
$topic->topic_title = $topic_data['topic_title'];
$topic->topic_time = $topic_data['topic_time'];
$topic->topic_poster = $topic_data['topic_poster'];
$topic->topic_first_post_id = $topic_data['topic_first_post_id'];
$topic->topic_first_poster_name = $topic_data['topic_first_poster_name'];
$topic->topic_first_poster_colour = $topic_data['topic_first_poster_colour'];
$topic->topic_last_post_id = $topic_data['topic_last_post_id'];
$topic->topic_last_poster_id = $topic_data['topic_last_poster_id'];
$topic->topic_last_poster_name = $topic_data['topic_last_poster_name'];
$topic->topic_last_poster_colour = $topic_data['topic_last_poster_colour'];
$topic->topic_last_post_subject = $topic_data['topic_last_post_subject'];
$topic->topic_last_post_time = $topic_data['topic_last_post_time'];
$topic->topic_last_view_time = $topic_data['topic_last_view_time'];
$topic->topic_bumped = $topic_data['topic_bumped'];
$topic->topic_bumper = $topic_data['topic_bumper'];
$topic->poll_title = $topic_data['poll_title'];
$topic->poll_start = $topic_data['poll_start'];
$topic->poll_length = $topic_data['poll_length'];
$topic->poll_max_options = $topic_data['poll_max_options'];
$topic->poll_last_vote = $topic_data['poll_last_vote'];
$topic->poll_vote_change = $topic_data['poll_vote_change'];
if ($load_posts) {
$sql = "SELECT * FROM " . POSTS_TABLE . " WHERE topic_id=" . intval($topic_id) . " ORDER BY post_time ASC";
$result = $db->sql_query($sql);
while ($post_data = $db->sql_fetchrow($result)) {
$topic->posts[] = post::from_array($post_data);
}
$db->sql_freeresult($result);
}
return $topic;
}