can this php function be written to perform better? I have this function takes a long time to complete. Is there a way i can improve it to quicken the procedure

function do_updatebonus() {
    global $site_config;

    $res200 = SQL_Query_exec("SELECT DISTINCT userid FROM peers WHERE seeder = 'yes'");

    while ($row200 = mysql_fetch_assoc($res200)) {
        $userid = $row200["userid"];
        $res201 = SQL_Query_exec("SELECT COUNT(torrent) FROM peers WHERE seeder = 'yes' AND userid = $userid");

        $c = mysql_result($res201, 0);
        if ($c &gt;= 5) {
            SQL_Query_exec("UPDATE users SET seedbonus = seedbonus + '" . $site_config["bonuspertime"] . "' WHERE id = $userid");
        }
    }
}
Yeah, you can optimize your query,

 $res201 = SQL_Query_exec("SELECT COUNT(torrent) FROM peers WHERE seeder = 'yes' AND userid = $userid");


As this query will first check for seeder which has 'yes' and then for userid. So you can first check for userid, then for seeder. This will improve performance

$res201 = SQL_Query_exec("SELECT COUNT(torrent) FROM peers WHERE userid = $userid" AND seeder = 'yes' );