-7

所以现在当我从 DB 获得积分时,我想将 5 个积分添加到 [points] 并保存到 DB:

function addPoints($email)
{
    $con = mysql_connect("example", "example", "example") ;
    if (!$con)
    {
        die("Can not connected: " . mysql_error());
    }
    mysql_select_db("example",$con);
    $sql = "SELECT points FROM tablename WHERE email = '$email'";
    $myData = mysql_query($sql,$con);
    while($record = mysql_fetch_array($myData))
    {
        $record['points'];      
    }
    mysql_close($con);
}
4

3 回答 3

1

UPDATE您可以使用查询完成相同的操作

UPDATE tablename SET points = points + 5 WHERE email = 'your_email_here'
于 2013-07-22T12:36:31.473 回答
1

尝试:

$newPoints = $record['points'] + 5;
$sql = "UPDATE tablename SET points = '$newPoints' WHERE email = '$email'";
mysql_query($sql,$con);
于 2013-07-22T12:39:56.990 回答
0

你可以修改你的while循环来实现这一点。

while($record = mysql_fetch_array($myData)){
    $points = $record['points'];    
$query = "update tablename set points=". $points +5 ." WHERE email = '$email'";
mysql_query($query, $con);      
}
于 2013-07-22T12:40:04.393 回答