有沒有辦法運行一個PHP函數「fun();」只有登錄用戶多次訪問頁面時才使用一次?運行PHP函數一次
這裏是函數。
<?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();
}
}
?>
如果您可以使用PHP5,則可以使用singleton/class/__構造。我不確定如何使用PHP4來做到這一點。 – Steven