I’ve got tenant portal when I need to show running balance for each transaction.
Here’s query I’ve written which does what I need it to do.
Problem I’ve got is that it doesn’t work in WordPress. Here’s my code:
if (is_user_logged_in()) {
$user = wp_get_current_user();
$balance = $wpdb->query(
$wpdb->prepare(
set @csum := "SELECT current_balance FROM exp_ten WHERE tenant_number = . (int) $user->ID";
select tenant_number, transaction_amount, (@csum := @csum + transaction_amount) as narrative
from exp_tran
order by tenant_number;
)
);
and here is the error I get:
Parse error: syntax error, unexpected ‘@’, expecting ‘,’ or ‘)’ in /home/path-to-the-file.php on line 165
Could anyone please help how to change query so it would be accepted by WordPress. If I’m right problem is that WordPress doesn’t accept mysql variable @csum.
Thanks in advance fro your help.