I tried something myself. Can anyone check my code pls?
Code: Select all
if ($config['milestone_pgoal'] == $config['num_posts'])
{
$sqlarray = array(
'SELECT' => '*',
'FROM' => MILESTONES_TABLE
'WHERE' => '`milestone`= ' . $config['num_posts'] . 'AND `type`=1'
);
$result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary));
if(mysql_num_rows($result)<1){
// Determine author of latest post
$sql_ary = array(
'SELECT' => 'u.user_id, u.username, u.user_colour, p.poster_id, p.post_id',
'FROM' => array(
USERS_TABLE => 'u',
POSTS_TABLE => 'p',
),
'WHERE' => 'u.user_id = p.poster_id AND p.post_id = (SELECT MAX(post_id) FROM ' . POSTS_TABLE . ')'
);
$result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary));
$achiever = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$sql = 'INSERT INTO ' . MILESTONES_TABLE . ' ' . $db->sql_build_array('INSERT', array(
'user_id' => $achiever['user_id'],
'milestone' => $config['milestone_pgoal'],
'type' => 1
));
$db->sql_query($sql);
}
set_config('milestone_pid', $achiever['user_id']);
set_config('milestone_puser', $achiever['username']);
set_config('milestone_pcolour', $achiever['user_colour']);
set_config('milestone_posts', $config['milestone_pgoal']);
set_config('milestone_pgoal', $config['milestone_pgoal'] + $config['milestone_pinc']);
}