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