Jump to content

no results


DrTrans

Recommended Posts

when i run the function, I want it basically spit out

 

$month = MONTHNAME(payment_date);

$amount = SUM(payments)

 

Basically want it to spit out months and amount for that month..

 

Can you please assist. Thanks in advance.

 

function operatingyear() {
       print "<center><h3> OPERATING STATMENT REPORT [12-Month]</h3></center>";
       print "<hr>";
       print "<br />";
   
        getconnect();
        $active = "1";
        $query9 = "SELECT MONTHNAME(payment_date), SUM(payment) FROM payments GROUP BY YEAR(payment_date), MONTH(payment_date)";
        $result9 = mysql_query($query9);
    $sum = mysql_result($result9,0);
        }

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/265484-no-results/
Share on other sites


function operatingyear($daterange) {
   global $loginid;	
   global $daterange;   
       print "<center><h3> OPERATING STATMENT REPORT [12-Month]</h3></center>";
       print "<hr>";
       print "<br />";
   
        getconnect();
        $active = "1";
        $query9 = "SELECT MONTHNAME(pay_date), SUM(pay_amount) FROM payments GROUP BY YEAR(pay_date), MONTH(pay_date)";
        $result9 = mysql_query($query9) or die( mysql_error() );
    $sum = mysql_result($result9,0);
        
        print "$sum";
        
    

   	
}

 

Fixed the Mysql errors. However it still not putting out any information.  This is my first time working with SUM.

Link to comment
https://forums.phpfreaks.com/topic/265484-no-results/#findComment-1360603
Share on other sites

What's your database look like?

 

Here's my sample database

 

CREATE TABLE IF NOT EXISTS `sometable` (
  `date` date NOT NULL,
  `amount` decimal(8,2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `sometable`
--

INSERT INTO `sometable` (`date`, `amount`) VALUES
('2012-07-10', '10.50'),
('2012-06-04', '15.25'),
('2012-07-19', '18.75'),
('2012-06-10', '5.50'),
('2012-07-06', '8.25');

 

And the following code...

<?php

mysql_connect('localhost','root','');
mysql_select_db('db');

$q = 'SELECT MONTHNAME(date), SUM(amount) FROM sometable GROUP BY YEAR(date), MONTH(date)';
$r = mysql_query($q) or die(mysql_error());

$sum = mysql_result($r,0);
echo $sum;


?>

 

... outputs

June

 

This is the way it should behave.

Link to comment
https://forums.phpfreaks.com/topic/265484-no-results/#findComment-1360608
Share on other sites

My db looks exactly the same, However, no results from the "echo"....

 

My Database:


pay_amount   |   pay_date |  pay_controller
----------------------------------------------------------
    107.13           2012-07-07         +
     98.10            2012-07-07          -
   

 

i even copied ur code and edited the fields in mysql statement to

 

 


function operatingyear($daterange) {
       print "<center><h3> OPERATING STATMENT REPORT [12-Month]</h3></center>";
       print "<hr>";
       print "<br />";
   
        getconnect();
        $q = 'SELECT MONTHNAME(pay_date), SUM(pay_amount) FROM payment GROUP BY YEAR(pay_date), MONTH(pay_date)';
        $r = mysql_query($q) or die(mysql_error());
        $sum = mysql_result($r,0);
        echo $sum;        
    

   	
}

 

 

Link to comment
https://forums.phpfreaks.com/topic/265484-no-results/#findComment-1360622
Share on other sites

There's a lot going on in your code that you haven't posted, so it's impossible to help.

 

Try copying and pasting directly, only changing the MySQL info and columns/table.

 

Also, try echoing mysql_num_rows to see if your SELECT statement is actually grabbing any rows.

Link to comment
https://forums.phpfreaks.com/topic/265484-no-results/#findComment-1360628
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.