mardi 28 juin 2016

How can I create a dynamic condition?

Here is my current code:

/* A part of index.php content */

if( time() - $_SESSION["TimeUpdateRep"] >= max(100 - $_SESSION["Reputation"] / 100, 20) ) {

    $smt = $db->prepare('SELECT reputation, notification FROM users WHERE id = ? limit 1');
    $smt->execute(array($_SESSION["Id"]));
    $num_row = $something->fetch();
    $_SESSION["Reputation"]        = $num_row['reputation'];
    $_SESSION["Notification_numb"] = $num_row['notification'];
    $_SESSION["TimeUpdateRep"]     = time();

}

/* note:
 * This line of code executes once before code above when user logs in
 * $_SESSION["TimeUpdateRep"] = time();
 */

As you see, code above updates the number of reputation and notification for each user based on a dynamic period. My current code depends on the number of user's reputation. The user who has more reputation, then that updating will be happened for him earlier.

So please focus on this line:

if( time() - $_SESSION["TimeUpdateRep"] >= max(100 - $_SESSION["Reputation"] / 100, 20) ) {

Actually my codes works as well, just it isn't tangible. I mean there isn't any obvious different in that updating between userA (1 rep) and userB (10k rep). (the different is just a few seconds)

How can I make a huge different between newcomer users, average users and super users in updating their reputations and notifications?

Aucun commentaire:

Enregistrer un commentaire