我已经创建了一个名为"store“的SQL表。我有29个字段。表中的少数字段依赖于表中其他字段的值。示例如下:
我有一个名为sell_rap_back的字段和一个名为just rap_back的字段。rap_back字段值是独立的,并已输入到数据库中,但我的sell_rap_back依赖于rap_back,计算方式为rap_back +5
Given : 'rap_back'
Calculate : 'sell_rap_back'
where
**sell_rap_back = rap_back+5**我正在用php/mysql实现它。具体实现如下:
//calculate the value
$qry1 = mysql_query("SELECT rap_back + 5 from store") or die(mysql_error());
//retrieve the value of qry1 and store it in a variable
$sell_rap_back = mysql_fetch_array($qry1);
// now I need to insert the value into the table and update it..
mysql_query("INSERT INTO store(sell_rap_back) VALUES('$sell_rap_back')");表未在此处更新..
现在,我不知道如何处理我的'sell_rap_back‘字段,并在'rap_back’一更新就将它存储在数据库中,直到我下一个事务发生。有人能帮我解决这个问题吗。
发布于 2012-08-18 03:11:10
不要使用固定字符串作为“失败”消息。它们对调试毫无用处。如果查询出了问题,MySQL会告诉你出了什么问题:
$qry1 = mysql_select("SELECT ...") or die(mysql_error());
^^^^^^^^^^^^^在你尝试这个之前,你的问题是无法回答的。从表面上看,查询看起来很好--没有语法错误,没有保留字。
https://stackoverflow.com/questions/12011772
复制相似问题