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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:05:15+00:00 2026-05-27T11:05:15+00:00

My code is so far $limitText =; if($history_length){ $limitText = ‘ limit ‘. $history_length;

  • 0

My code is so far

        $limitText ="";
        if($history_length){
            $limitText = ' limit '. $history_length;
        }

        if(!$history_days){
            $history_days = '180';
        }
$db = $this->getInvokeArg('bootstrap')->getPluginResource('db')->getDbAdapter();
        //changing code to add min(currBalance) -- as sum(points) is valid only for debit. Also sort by desc instead of  (major bug)
        $history_stmt = $db->query("SELECT sum(points) as points,credit_date,min(currBalance) as currBalance,extRefId,transactedAt,pointType FROM credits where userid = '".$userid."' and credit_date >= date('now','-".$history_days." days')  group by extRefID,pointType order by creditid desc ".$limitText);
        $history_results = $history_stmt->fetchall();

        $expiry_stmt = $db->query("SELECT availablePoints,expiry_date FROM credits where userid = '".$userid."'and availablePoints > 0 and expiry_date <= date('now','+".$expiry_duration." days') order by expiry_date asc ");
        $expiry_results = $expiry_stmt->fetchall();

I got an error

<b>Message:</b> SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''-180 days')  group by extRefID,pointType order by creditid desc' at line 1  </p>

what i can do I am not able to fine the solution

  • 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-27T11:05:16+00:00Added an answer on May 27, 2026 at 11:05 am

    Seems you are using the MySQL Date function in a wrong way – were you actually planning on using the php date function instead? Instead of e.g.

    "[...] credit_date >= date('now','-".$history_days." days')  group by [...]"
    

    you’d have to write:

     "[...] credit_date >= '".date('-'.$history_days.' days')."' group by [...]"
    

    Only variables (e.g. $history_days) will get expanded by php in a string enclosed with double quotes (“), but not function calls. If you enclose a function call inside the string, php can’t recognize it, and it will be passed as is to mysql, instead of first being executed by php; but you want php to evaluate it, so you’ll have to exclude it from the string constant and add it with the concatenation operators (.) to your string.

    Your php date function call however also seems to be incorrect; to get “the current date minus a certain amount of days”, best use mysql date functions like this:

     "[...] credit_date >= DATE_SUB(NOW(), INTERVAL '$history_days' DAY) group by [...]"
    

    And just one general note on security: It’s not clear from the piece of script you’re providing, but if the values in $history_days, $history_length, $user_id or $expiry_duration (the variables used inside the SQL statement) have only the remotest chance of being set by the user, you should not insert them directly into an SQL statement, but do something to prevent SQL injection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code so far which perfectly but relies on there being a
This is what I have as far as code, it is in the first
Another thanks to SLaks for helping me get the code this far. I'm not
Here is my code so far now i want to combine this what i
This is my code so far: <form> <p>Username: </p><input type=text name=username /> <p>Password: </p><input
This is my Code so far. I want to know how to return the
I'm trying to create the following design: This is my code so far. <section
This is my code so far: http://jsfiddle.net/zY3xx/ I have a blank option in all
I have the following code so far: /* * This method adds only the
this is my code so far, what I'm trying to do is process the

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.