php
  • mysql
  • oop
  • 2016-11-18 16 views 0 likes 
    0

    我想要得到在一个特定的一个月所做的支付的总和可以说从1月至3月在我的网站。 我的表是设备有钱和加入列,但加入列有日期和时间。 如果可能,我想使用这种方法,但是这个片段是用于奖品总和的。我怎样才能得到在某个月的所有产品的总和在mysql

    if(isset($ _ POST ['moneyMade'])){ $ moneyMade = 0;

    $query = "select SUM(Money) from users where Joined<='2016-11-01 00:00:00' and Joined>='2016-11-31 00:00:00'"; 
    //if (!$query) { echo 'MySQL Error: ' . mysqli_error(); exit; } 
    //$query="select * from equipments "; 
    $result = mysqli_query($conn,$query); 
    
    
    
    while ($row = mysqli_fetch_assoc($result)){ /* Fetch a result row as an associative array */ 
    /*while ($row = mysqli_result($result)){*/ 
        $moneyMade +=$row['Money']; 
    
    
    } 
    
    echo "Money made for this month is ". $moneyMade; 
    
        } 
    

    我怎样才能实现这一点使用PHP和一些SQL? 谢谢。

    +0

    显示您的查询或您已经完成的工作 – Karthi

    +0

    分享一些虚拟数据和您尝试的查询? –

    +0

    尝试像这样'select SUM(amt)from tab_name where DateTime' <='2016-11-01 00:00:00'和DateTime> = 2016-11-31 00:00:00'。 ** – Karthi

    回答

    0

    假设Prize是一个数值,你可以做如下的事情。

    $month = 'January'; 
    
    $month_start = strtotime("first day of {$month}"); 
    $month_end = strtotime("last day of {$month}"); 
    
    $query = "SELECT SUM(`Prize`) FROM `equipments` WHERE UNIX_TIMESTAMP(`Joined`) >= {$month_start} AND UNIX_TIMESTAMP(`Joined`) <= {$month_end}"; 
    
    +0

    OP期望从特定月份获得数据总和。但你想念那个。 – Karthi

    +0

    @Jayme Brereton我想要具体数据的结果不是总数 –

    +0

    我的不好。我已经更新了答案。 –

    相关问题