是否有可能以某种方式计算一个表的两行之间的差异?
我尝试了这个,但它不起作用:
$diff = mysql_num_rows("
SELECT (`used`-`paid`)
FROM `coupons_codes`
WHERE `cid`='".$data['cid']."'");
答案 0 :(得分:0)
你应该这样做:
//store the query in a string
$query = "SELECT `used`-`paid` FROM `coupons_codes` WHERE `cid`='".$data['cid']."'";
//execute the query on the MySQL database
$result = mysql_query($query);
//extract the result from the response from the MySQL server
$diff = mysql_result($result, 0, 0);
您正在使用的函数用于计算从mysql_query();
调用获得的结果集中的行数。
我建议您尝试阅读有关PHP和MySQL的一些基础知识,我觉得您缺乏一些基本知识来真正创建好的代码。