开发者

Help with a PHP script

I'm 开发者_高级运维trying to create a custom medals/awards system for a bulletin board script.

The part I'm having issues with is the task that runs every 10 minutes to check for users who are eligible for medals.

Here's my current code:

// select all medals from database
$query = $db->simple_select("medals", "*", "");
$medals = $db->fetch_array($query);

// select users
$query_users = $db->simple_select("users", "*", "");
$results = $db->fetch_array($query_users);

foreach($medals as $medal)
{
    foreach($results as $result)
    {
        if($result['postnum'] >= $medal['postnum'])
        {
            $insert = array( 
                "mid" => $medals['id'],
                "muid" => $result['uid'],
                "mtime" => TIME_NOW,
            ); 

            $db->insert_query("users_medals", $insert);                 
        }
    }
}

The intention for the above code is to query the medals table which holds all the medals which eligible to be "won" by users. The users table is pretty self explanatory - it holds the users of the forum board. When users have meet the requirements for a medal, the medal is inserted into the user_medals table with the medal id, user id, and the time the medal was awarded.

However, each time the task is ran, it inserts over 30 rows (I'm using a test board with only two users, so it should only be inserting 1 row, as only 1 user has met the requirements for the medal for users with at least 2 posts).

Could someone help me with this?

Thanks.


The problem is here:

if($result['postnum'] >= $medal['postnum'])

Output the value of $result['postnum'] and $medal['postnum'] with each loop to examine their values. You will find that the first value is always greater than or equal to the second value, so the loop always executes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜