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 9080965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:12:02+00:00 2026-06-16T20:12:02+00:00

Cannot write a complete function to compare current month and year to my database

  • 0

Cannot write a complete function to compare current month and year to my database m/y. The dates in the database are from the now() function. I want to sum the costs based on this comparison. Something like:

$currentDate = date("Y-m");
$query = mysql_query ("SELECT SUM(cost) FROM memberorders WHERE 
         memberNumber=$memNum AND 
        (SELECT DATE_FORMAT(orderDate, '%Y-%m'))=$currentDate");

But that’s not working. Then I need help with a function to sum it up.

$test1 = mysql_fetch_array($query);
$total = $test1[0];

Would that work for going through the database and summing it up?

  • 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-06-16T20:12:03+00:00Added an answer on June 16, 2026 at 8:12 pm

    Don’t do that, don’t apply any function (like the DATE_FORMAT() function) to a column (like the OrderDate column) if you want indexes to be used. Try this if you can create the fixed starts of months in the application (PHP) code:

    SELECT SUM(cost) 
    FROM memberorders 
    WHERE memberNumber = $memNum 
      AND orderDate >= '2013-01-01'      -- first day of this month
      AND orderDate < '2013-02-01' ;     -- first day of next month
    

    or this if you prefer to handle it in MySQL:

    SELECT SUM(cost) 
    FROM memberorders 
    WHERE memberNumber = $memNum 
      AND orderDate >= LAST_DAY(NOW()) + INTERVAL 1 DAY - INTERVAL 1 MONTH 
      AND orderDate < LAST_DAY(NOW()) + INTERVAL 1 DAY ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that I want to write and cannot work out how
ANSWER: You cannot write an int directly to a file. Convert it to a
Can someone tell me why I cannot write a class as follows <?php class
I cannot seem to write to a file. I create the file and directory
I cannot figure out how to write the following query using the DbFinderPlugin 1.2.2
This script cannot find bannersize unless I write <div id=bannersize></div> before the javascript. The
I cannot figure out why the following simple program doesn't (create) and then write
0x80040237 Cannot insert duplicate key. I'm trying to write an import routine for MSCRM4.0
I am trying to write my thesis in latex... Cannot get the layout straight
How to write a getter that can not be deleted? I want to own

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.