PHP根据条件更新所有用户

时间:2011-08-01 19:05:15

标签: php mysql sql

我已经建立了一个体育选秀网站,我无法弄清楚如何根据他们所做的特定选择更新所有用户分数。我必须一次更新一个用户并多次触发相同的脚本。 (当我登录时脚本会触发,然后我再次限制它被禁止)

- 在这个例子中,我只能更新用户'robert'。我有一个包含函数的包含文件的php文件 -

我将非常感谢任何帮助!

PHP文件:

<?php


$connect = //connect to database

//ACCESS PERMISSION
$sql = "SELECT * FROM access WHERE username = 'bj'";

$query = mysql_query($sql,$connect);

if ($query) {

while ($row = mysql_fetch_assoc($query))
    {
        $activated = $row['sf'];

if($activated=='1')
{
//END ACCESS PERMISSION EXCEPT CLOSE
//loop declare begin
$quer = "SELECT * FROM sffedorvsdan WHERE username = 'robert'";

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 



include('update2.php');

//PICK 1 START
more($pick1);

//PICK 2 START
more($pick2);

//PICK 3 START
more($pick3);

//PICK 4 START
more($pick4);

//PICK 5 START
more($pick5);

}
}else{
echo mysql_error();
}




//RESTRICT ACCESS
mysql_query("UPDATE access SET sf ='2'
WHERE username = 'bj'");
}
}
}


?>

包含包含功能的文件

<?php

function more($pick)
{

global $connect, $pick1, $pick2, $pick3, $pick4, $pick5, $pick6 ;

//connect to database

if($pick=='11'||$pick=='22'||$pick=='13'||$pick=='14'||$pick=='25') //True Picks
{
$score = mysql_query("UPDATE stats SET score = (score + 10), mmascore = (mmascore + 10), mmawins = (mmawins + 1), mmagames = (mmagames + 1), wins = (wins + 1), games = (games + 1)
WHERE username = 'robert'");

return $score;
}
else if($pick=='21'||$pick=='12'||$pick=='23'||$pick=='24'||$pick=='15') //False Picks
{
$score2 = mysql_query("UPDATE stats SET score = (score - 5), mmascore = (mmascore - 5), mmagames = (mmagames + 1), games = (games + 1)
WHERE username = 'robert'");

return $score2;
}



}

?>

1 个答案:

答案 0 :(得分:0)

UPDATE stats SET score = score + CASE 
WHEN username='robert' THEN -5
WHEN username='RiaD' THEN 100500
WHEN username='Shef' THEN 6514
ELSE 0 END