Run PHP Function once
<p>Is there a way to run a PHP FUNCTION "fun();" only once when a logged in user accesses a page multiple times?</p>

<p>here is the function.</p>

<pre><code>&lt;?php

$connect = //connect to database

function fun()
{

    //loop declare begin
    $quer = "SELECT * FROM sffedorvsdan WHERE username = '$_SESSION[username]'";

    if($quer_run = mysql_query($quer))
    {
        while($row = mysql_fetch_assoc($quer_run))
        {
            $pick1 = $row['pick1'];
            $pick2 = $row['pick2'];
            $pick3 = $row['pick3'];
            $pick4 = $row['pick4'];
            $pick5 = $row['pick5'];
            $pick6 = $row['pick6']; 

            //loop end EXCEPT CLOSE 

            $user = $_SESSION['username'];

            if($pick1 == '11')
            {

                $score = mysql_query("
                    UPDATE stats SET score = (score + 10), mmascore = (mmascore + 10), 
                    wins = (wins + 1), games = (games + 1)
                    WHERE username = '$user'
                ");

                return $score;
            } 
            else if($pick1 == '21')
            {
                $score2 = mysql_query("
                    UPDATE stats SET score = (score - 5), mmascore = (mmascore - 5), 
                    games = (games + 1)
                    WHERE username = '$user'");

                return $score2;
            }
        }
    }else{
        echo mysql_error();
    }
}

?&gt;
</code></pre>
