所以现在当我从DB获得积分时,我想在[积分]上加5分并保存到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);
}
答案 0 :(得分:1)
您可以使用UPDATE
查询
UPDATE tablename SET points = points + 5 WHERE email = 'your_email_here'
答案 1 :(得分:1)
尝试:
$newPoints = $record['points'] + 5;
$sql = "UPDATE tablename SET points = '$newPoints' WHERE email = '$email'";
mysql_query($sql,$con);
答案 2 :(得分:0)
您可以在循环时修改您以实现此目的。
while($record = mysql_fetch_array($myData)){
$points = $record['points'];
$query = "update tablename set points=". $points +5 ." WHERE email = '$email'";
mysql_query($query, $con);
}