Jump to content

display totals from previous month


ianhaney
Go to solution Solved by ianhaney,

Recommended Posts

Hi

 

I am trying to output the job_cost and profit from the previous month but am getting no output, I have the following coding

<table class="dashboard">
<tr>
<th colspan="5">Total Jobs Cost and Profit Made(Month)</th>
</tr>
<tr>
<th>Month</th>
<th>Total Job Costs</th>
<th>Total Profit Made</th>
</tr>

<?php
$hostname="";
$username="";
$password="";
$db = "";
$dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password);
foreach($dbh->query('SELECT SUM(job_cost, profit) as job_cost, profit FROM repairs WHERE exrdate >= exrdate(exrdate, INTERVAL 1 MONTH') as $row) { 
?>

<tr>
<td><?php echo $row['date_of_repair']; ?></td>
<td><?php echo $row['job_cost']; ?></td>
<td><?php echo '£' . $row['profit']; ?></td>
</tr>
<?php
}
?>
</table>

I know it is the SELECT query where I have messed up on somewhere but is about it, I am not sure what it should be, sorry

 

Thank you in advance

 

Ian

Link to comment
Share on other sites

Sorry last one, is it possible to display the current Month word in the table

 

I have the following code

<tr>
<td><?php echo $row['exrdate']; ?></td>
<td><?php echo $row['job_cost']; ?></td>
<td><?php echo '£' . $row['profit']; ?></td>
</tr>

If possible to have the word November displayed where the first td row is?

Link to comment
Share on other sites

I got the following now but is not outputting the month name

SELECT SUM(job_cost) as job_cost, SUM(profit) as profit FROM repairs WHERE MONTHNAME(exrdate) = MONTHNAME(CURDATE()) AND YEAR(exrdate) = YEAR(CURDATE())

do I need to add MONTHNAME after as profit

Edited by ianhaney
Link to comment
Share on other sites

mysql> SELECT MONTHNAME('2008-02-03');

-> 'February'

 

do I directly add that into the SELECT query?

Of course you don't (unless you want "February" output every time). That is what is known as "an example". Strangely, the writers of the MySQL manual did not know that your date field would be "exrdate", so you need to substitute that yourself.

SELECT MONTHNAME(exrdate) as month, ....

then you would output it with " $row['month'] "

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.