Sum table1 $ date1和$ date2之间AND用户名等于$ user

时间:2014-10-11 18:58:31

标签: php mysql sql select sum

你好我有这个总和的一些问题选择有没有人知道这有什么不对,似乎我没有得到它的结果

$result = mysql_query("SELECT SUM(total)   
FROM table1 where   date BETWEEN '".$date1." 00:00:00' AND '".$date2." 23:59:59' and  username = ".$user."");  
 while($row=mysql_fetch_array($result))  
{  $sum = $row['SUM(total)'];}

1 个答案:

答案 0 :(得分:0)

尝试

$query = "SELECT SUM(total) AS result   
          FROM table1 
          WHERE DATE(date) BETWEEN '$date1' AND '$date2' 
          AND username = '$user'"; 

$con = \\your db connection string
$result = mysql_query($con,$query);

while($row=mysql_fetch_array($result))  
{$sum = $row['result'];}