如何在PHP中显示完整的月份日期和金额?

时间:2014-02-01 09:24:50

标签: php mysql date

我想在php中创建一个xml字符串,

我希望交易date=$dates然后交易日期和相关金额显示在数据库和

如果事务date!=$dates然后$date存储在标签中,金额= 0我是如何做到的

这是我的PHP代码:

    <?php
function default1()
{
     $dates = array();
     $timestamp = time();
     for ($i = 1 ; $i <=30 ; $i++) 
     {
        $dates[$i]= date('Y-m-d', $timestamp) . '<br />';
        $timestamp -= 24 * 3600;
     }

        print_r ($dates);
    //echo date('Y-m-d', strtotime('-7 days'));
        $strQuery="select Distinct DATE_FORMAT(transactions.transaction_date,'%c-%d-%Y') as transaction_date,sum(amount)as Amount from transactions group by  DATE_FORMAT(transactions.transaction_date,'%c-%d-%Y')";       
        $result = $GLOBALS ['mysqli']->query ($strQuery) or die ($GLOBALS ['mysqli']->error . __LINE__);
        $strXML = "<chart caption='Reports of transactions' xAxisName='Date' yAxisName='Amount' showValues='0' useRoundEdges='1' palette='3'>";
        while($ors = $result->fetch_assoc ())
        {
            for ($i = 1 ; $i <=30 ; $i++)
            {
                if(in_array("'".$ors['transaction_date']."'", $dates[$i]))
                {
                    $strXML .= "<set label='" .$ors['transaction_date'] ."' value='" . $ors['Amount'] ."' />";
                }
                else
                {
                    $strXML .= "<set label='" .$dates."' value='0' />";
                }
            }
        }
        $strXML .= "</chart>";
        ?>
        <textarea><? print_r($strXML); ?></textarea>
     <?             
}

&GT;

1 个答案:

答案 0 :(得分:1)

请尝试此查询,

if(sum(amount)= 0,0,sum(amount))as Amount

$strQuery="select Distinct DATE_FORMAT(transactions.transaction_date,'%c-%d-%Y') as transaction_date,if(sum(amount)=0,0,sum(amount))as Amount from transactions group by  DATE_FORMAT(transactions.transaction_date,'%c-%d-%Y')";