我必须编写两条 SQL 语句才能更新一条记录,有更好的方法吗?
我想更新一个表:
$result=mysql_query("select balance from tablename where userid='$userid")or die(mysql_error());
$row=mysql_fetch_assoc($result);
$accountbalance=$row['balance'];
if($accountbalance>$cost)
{
$result=mysql_query("update tablename set balance-'$cost' where userid='$userid")or die(mysql_error());
}
else {
...
}
你看,我必须写两条mysql语句,有更好的方法吗?
mysql_query("update users set balance=balance+'$pwbalance'-'$totalprice' where memberid='$memberid' and (balance+'$pwbalance'-'$totalprice')>=0")or die(mysql_error());
$count=mysql_affected_rows();
为什么 $count 是 0,尽管我认为它应该是 1?
I want to update a table:
$result=mysql_query("select balance from tablename where userid='$userid")or die(mysql_error());
$row=mysql_fetch_assoc($result);
$accountbalance=$row['balance'];
if($accountbalance>$cost)
{
$result=mysql_query("update tablename set balance-'$cost' where userid='$userid")or die(mysql_error());
}
else {
...
}
You see, I have to write two mysql statements, is there a better way to do it?
mysql_query("update users set balance=balance+'$pwbalance'-'$totalprice' where memberid='$memberid' and (balance+'$pwbalance'-'$totalprice')>=0")or die(mysql_error());
$count=mysql_affected_rows();
Why is $count is 0 even I think it should be 1?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)