Php 如何在两列之间获得总价?
例如: $from=30和$to=33。 现在我想得到的总价格介于$from和$to之间 这是我的密码Php 如何在两列之间获得总价?,php,mysql,Php,Mysql,例如: $from=30和$to=33。 现在我想得到的总价格介于$from和$to之间 这是我的密码 $from = $_POST['from']; $to = $_POST['to']; $result = mysql_query("SELECT SUM(price) as totalPrice FROM price WHERE price BETWEEN '$from' and '$to'"); $row = mysql_fetch_assoc($result); $sum = $ro
$from = $_POST['from'];
$to = $_POST['to'];
$result = mysql_query("SELECT SUM(price) as totalPrice FROM price WHERE price BETWEEN '$from' and '$to'");
$row = mysql_fetch_assoc($result);
$sum = $row['totalPrice'];
…根据您的需要,可能会更改或更改。请发布您尝试过的代码。我们是来帮助您的,但我们不会为您编写完整的代码!您需要更加具体,并提供结果。从表中选择to=33和from=30@pamblam不要用或来理解逻辑。。好吧,OP可以更好地解释,请再次检查我的代码并建议我…不需要使用sum,当我试图在数据库中应用您的代码时,它将不会或它给出空结果。我需要在30和33之间的总价格30和33是不具体的。我还忘了在backticks中输入from列,但我知道如何在手机上做backticks
SELECT price as total FROM yourtable WHERE from = 30 AND to = 33
SELECT price as total FROM yourtable WHERE from = 30 AND to = 33