From 6cc36dc266d51c1159bcd6b608afa504a4f4a3ee Mon Sep 17 00:00:00 2001 From: pioder Date: Fri, 1 May 2009 20:52:43 +0000 Subject: [PATCH] Changed generating lastpost in topic and forum. git-svn-id: https://svn.pioder.pl/uf-svn/uF@19 72ec579a-5ced-4fa4-82f3-afba5d98df2f --- includes/cache/cache_forums.php | 4 +-- includes/cache/cache_index.php | 4 +-- includes/misc_functions.php | 63 +++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/includes/cache/cache_forums.php b/includes/cache/cache_forums.php index d07fd02..c35d426 100644 --- a/includes/cache/cache_forums.php +++ b/includes/cache/cache_forums.php @@ -29,7 +29,7 @@ while($result = @mysql_fetch_array($query)) { $count_topic[$result['t_id']]=$result['p_id']; } -$sql = "SELECT ".POSTS_TABLE.".*, ".USERS_TABLE.".* FROM ".POSTS_TABLE." LEFT JOIN ".USERS_TABLE." ON ".USERS_TABLE.".u_id = ".POSTS_TABLE.".u_id WHERE `f_id`='$fid' ORDER BY `ptime`"; +/*$sql = "SELECT ".POSTS_TABLE.".*, ".USERS_TABLE.".* FROM ".POSTS_TABLE." LEFT JOIN ".USERS_TABLE." ON ".USERS_TABLE.".u_id = ".POSTS_TABLE.".u_id WHERE `f_id`='$fid' ORDER BY `ptime`"; $query = DataBase::sql_query($sql,'GENERAL', 'Could not obtain amout of posts in forum'); while($result = @mysql_fetch_array($query)) { @@ -38,7 +38,7 @@ while($result = @mysql_fetch_array($query)) $lastpost[$result['t_id']]['time']=$result['ptime']; $lastpost[$result['t_id']]['user_nick']=$result['nick']; $lastpost[$result['t_id']]['user_rank']=$result['rank']; -} +} */ // //generate output pages // diff --git a/includes/cache/cache_index.php b/includes/cache/cache_index.php index ec65986..f2a46b1 100644 --- a/includes/cache/cache_index.php +++ b/includes/cache/cache_index.php @@ -15,7 +15,7 @@ if(!defined('IN_uF')) //cache forums and posts - version v1.0 Alpha 2--------------------------------- // //lastpost in forum cache -$sql = "SELECT ".POSTS_TABLE.".*, ".USERS_TABLE.".* FROM ".POSTS_TABLE." LEFT JOIN ".USERS_TABLE." ON ".POSTS_TABLE.".u_id = ".USERS_TABLE.".u_id GROUP BY `f_id`, `ptime` ORDER BY `ptime`"; +/*$sql = "SELECT ".POSTS_TABLE.".*, ".USERS_TABLE.".* FROM ".POSTS_TABLE." LEFT JOIN ".USERS_TABLE." ON ".POSTS_TABLE.".u_id = ".USERS_TABLE.".u_id GROUP BY `f_id`, `ptime` ORDER BY `ptime`"; $query = DataBase::sql_query($sql,'GENERAL','Could not obtain last post in topic', true); $post_count = @mysql_num_rows($query); while($result = @mysql_fetch_array($query)) @@ -26,7 +26,7 @@ while($result = @mysql_fetch_array($query)) $last_post[$result['f_id']]['time'] = $result['ptime']; $last_post[$result['f_id']]['user_rank'] = $result['rank']; $last_post[$result['f_id']]['user_nick'] = $result['nick']; -} +}*/ //cache forums --don't modify!!! $cache_id=1; $sql = "SELECT ".FORUMS_TABLE.".*, COUNT(".POSTS_TABLE.".p_id) as amout, ".POSTS_TABLE.".f_id AS count FROM ".FORUMS_TABLE." LEFT JOIN ".POSTS_TABLE." ON ".FORUMS_TABLE.".f_id= ".POSTS_TABLE.".f_id GROUP BY `f_id` ORDER BY `c_id`, `sort`"; diff --git a/includes/misc_functions.php b/includes/misc_functions.php index aaa99be..9045053 100644 --- a/includes/misc_functions.php +++ b/includes/misc_functions.php @@ -343,4 +343,67 @@ function ViewSkinName() return $result['name']; } +function GenerateLastPost($id, $type) +{ + $last_post = ''; + + switch ($type) + { + /** field lastpost in forum format + tp_id:u_id:t_id:ptime:rank:nick + */ + case 1: //for forum + { + $sql = "SELECT ".POSTS_TABLE.".*, ".USERS_TABLE.".* FROM ".POSTS_TABLE." LEFT JOIN ".USERS_TABLE." ON ".POSTS_TABLE.".u_id = ".USERS_TABLE.".u_id WHERE `f_id`='$id' ORDER BY `ptime` LIMIT 1"; + $query = DataBase::sql_query($sql,'GENERAL','Could not obtain last post in forum', true); + $post_count = @mysql_num_rows($query); + $result = mysql_fetch_array($query); + + $last_post .= $result['tp_id']; + $last_post .= ':'; + $last_post .= $result['u_id']; + $last_post .= ':'; + $last_post .= $result['t_id']; + $last_post .= ':'; + $last_post .= $result['ptime']; + $last_post .= ':'; + $last_post .= $result['rank']; + $last_post .= ':'; + $last_post .= $result['nick']; + + $sql = "UPDATE ".FORUMS_TABLE." SET + `lastpost`='$last_post' + WHERE `f_id`='$id'"; + DataBase::sql_query($sql,'GENERAL','Could not update lastpost in forum'); + break; + } + + /** field lastpost in topic format + tp_id:u_id:ptime:rank:nick + */ + case 2: //for topic + { + $sql = "SELECT ".POSTS_TABLE.".*, ".USERS_TABLE.".* FROM ".POSTS_TABLE." LEFT JOIN ".USERS_TABLE." ON ".USERS_TABLE.".u_id = ".POSTS_TABLE.".u_id WHERE `t_id`='$id' ORDER BY `ptime` LIMIT 1"; + $query = DataBase::sql_query($sql,'GENERAL', 'Could not obtain amout of posts in topic'); + $result = mysql_fetch_array($query); + + $last_post .= $result['tp_id']; + $last_post .= ':'; + $last_post .= $result['u_id']; + $last_post .= ':'; + $last_post .= $result['ptime']; + $last_post .= ':'; + $last_post .= $result['rank']; + $last_post .= ':'; + $last_post .= $result['nick']; + + $sql = "UPDATE ".TOPICS_TABLE." SET + `lastpost`='$last_post' + WHERE `t_id`='$id'"; + DataBase::sql_query($sql,'GENERAL','Could not update lastpost in topic'); + break; + } + } +} + ?>