0

是否有可能以某种方式计算一张表的两行之间的差异?

我试过这个,但它不起作用:

$diff = mysql_num_rows("
SELECT (`used`-`paid`) 
FROM `coupons_codes` 
WHERE `cid`='".$data['cid']."'");       
4

1 回答 1

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 的一些基础知识,我感觉您缺乏一些真正创建好的代码的基础知识。

于 2012-01-12T13:18:14.013 回答