Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 584213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:52:27+00:00 2026-05-13T14:52:27+00:00

I’ve got a minor problem with a database admin page that I use to

  • 0

I’ve got a minor problem with a database admin page that I use to update values and totals in a MySQL database for generating various figures and data for a website.

A bit of background – the database table in question holds fundraising totals for a charity bookstall, with the table having three columns – id, date, and amountraised. Summing the total raised for a specific year or the current year isn’t a problem – I’ve already got a running total from last February when the fundraising started and one for the current year, and that’s working fine. I’ve just realised though while adding in this week’s total raised that while I know the total of all funds raised, and how much has been raised so far this year, that nowhere is the total for last year shown. Obviously for this year I can just take the total to date for this year off the grand total, but I really need a total for each year to be shown.

I have a table displayed on the page that shows the fundraising targets for each year, and I want to add in the year total to that table so that over time we can see both the target for each year and amount raised that year.

In the bit of the page that displays the running total, I have the following, which display the grand total, and the total for the current year:


$result = mysql_fetch_array($query);
$sumtotal = $result["sum_total"];

$query2 = mysql_query("SELECT SUM(amountraised) AS year_total FROM fundraisingtotal WHERE YEAR(date) = YEAR(CURDATE());");
$result2 = mysql_fetch_array($query2);
$yeartotal = $result2["year_total"];
?>
<p class="dbpara">The current fundraising total since February 2009 is <b>&pound;<? echo "$sumtotal"; ?></b>.</p>
<p class="dbpara">The current fundraising total for this year (<?php echo date('Y'); ?>) is <b>&pound;<? echo "$yeartotal"; ?></b>.</p>

Also on the same page I have the display of the fundraising targets, and it’s this bit I’ve got the problem with, partly because the fundraising totals data’s in a separate table to the annual targets (annual targets are in a table with just the year and the target), and partly because the table that displays the annual target uses a while loop to write out the data from the database to the page. This is the code I’m using to write out the table and the data (I’ve put the table cell for the total raised in, but obviously no code for it):

<?php
$query="SELECT * FROM annualtarget ORDER BY year DESC";
$result=mysql_query($query);
$num = mysql_num_rows ($result);
if ($num > 0 ) {
$i=0;
while ($i < $num) {
$year = mysql_result($result,$i,"year");
$target = mysql_result($result,$i,"target");
$id = mysql_result($result,$i,"id");
echo "<tr><td class=\"yr\"> $year </td><td class=\"tg\"> &pound;$target </td><td class=\"total\"> ???? </td><td class=\"update\"><a href=\"updatetarget.php?id=$id\">Update</a></td><td class=\"delete\"><a href=\"delete.php?id=$id\">Delete</a></td></tr>";
++$i; } } else { echo "<tr><td colspan=\"4\">The database is empty!</td></tr>"; }
mysql_close();
?>

Obviously because I’ll need a different query to calculate the totals for the year, but I can’t work out how I can work that into the while loop. I could use the date from the fundraising amount table by separating out the year bit of the date, but as the target for each year is in a different table that wouldn’t work, and I really don’t want to have to hard-code the year and its total raised in the database just to display, when I can (if I can figure out how to do it) use the database to calculate it.

I’m probably missing something ridiculously obvious here, but I can’t figure it out. Has anyone any idea how I can do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:52:27+00:00Added an answer on May 13, 2026 at 2:52 pm
    SELECT a.year , SUM( f.amountraised ) , a.target
    FROM annualtarget a INNER JOIN  fundraisingtotal f ON (a.year = YEAR( f.date ))
    GROUP BY a.year
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 289k
  • Answers 289k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer AFAIK theres no libs for what you want to do… May 13, 2026 at 5:37 pm
  • Editorial Team
    Editorial Team added an answer Turns out the answer is simple: Stage { title: "XGrid… May 13, 2026 at 5:37 pm
  • Editorial Team
    Editorial Team added an answer This will be the default behaviour if you are using… May 13, 2026 at 5:37 pm

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.