create procedure update_forums() begin declare f int(8); declare counter_id int(8) default 0; declare t int(8); declare p_id int(8); declare pr_id int(8); declare p_sub varchar (100); declare p_time int(11); declare pr_name varchar(255); declare pr_col varchar(6); select count(*) into t from phpbb_forums; create temporary table tempo select * from phpbb_forums; while counter_id < t do select forum_id into f from tempo order by forum_id limit 1; select post_id into p_id from phpbb_posts where forum_id = f order by post_id desc limit 1; select poster_id into pr_id from phpbb_posts where forum_id = f order by post_id desc limit 1; select post_subject into p_sub from phpbb_posts where forum_id = f order by post_id desc limit 1; select post_time into p_time from phpbb_posts where forum_id = f order by post_id desc limit 1; select if(p.post_username='',u.username,p.post_username) into pr_name from phpbb_posts p join phpbb_users u on u.user_id=poster_id where forum_id = f order by post_id desc limit 1; update phpbb_forums set forum_last_post_id=p_id where forum_id = f ; update phpbb_forums set forum_last_poster_id=pr_id where forum_id = f ; update phpbb_forums set forum_last_post_subject=p_sub where forum_id = f ; update phpbb_forums set forum_last_post_time=p_time where forum_id = f ; update phpbb_forums set forum_last_poster_name=pr_name where forum_id = f ; delete from tempo where forum_id = f; set counter_id = counter_id + 1; end while; drop table tempo; end ?