idh63
Posts: 76
|
| Posted: 01/23/2008, 6:54 PM |
|
Hi Folks,
I have this query that return a single result. it works great in navicat phpmyadmin etc.
SELECT sum(transaction.deposit) - sum(transaction.withdraw) AS balance FROM transaction WHERE transaction.ex_date <= '$process_date' AND userid = $userid
with debug on the output to screen is:
SELECT sum(transaction.deposit) - sum(transaction.withdraw) AS balance FROM transaction WHERE transaction.ex_date <= '2007-7-22' AND userid = 572
The result should be 1573, but... it is always 1. here is the code in context...
$db2->query("SELECT sum(transaction.deposit) - sum(transaction.withdraw) AS balance FROM transaction WHERE transaction.ex_date <= '$process_date' AND userid = $userid");
$cur_balance = $db2->next_record();
$new_balance = $cur_balance + ($process_rate*$cur_balance);
echo "Cur bal: \$$cur_balance<br>";
I did originally have $cur_balance = $db2->query("select...... and I expected to have the value as $cur_balance.
Some help would be greatly appreciated.
Thanks
david
|
 |
 |
DonB
|
| Posted: 01/24/2008, 5:58 AM |
|
$cur_balance = $db2->next_record();
doesn't return the VALUE, it returns a resource id. The value is
$db2->f("balance").
--
DonB
http://ccswiki.gotodon.net
"idh63" <idh63@forum.codecharge> wrote in message
news:54797fdeeb2544@news.codecharge.com...
> Hi Folks,
>
> I have this query that return a single result. it works great in navicat
> phpmyadmin etc.
>
> SELECT sum(transaction.deposit) - sum(transaction.withdraw) AS
> balance
> FROM transaction WHERE transaction.ex_date <= '$process_date' AND userid =
> $userid
>
> with debug on the output to screen is:
> SELECT sum(transaction.deposit) - sum(transaction.withdraw) AS
> balance
> FROM transaction WHERE transaction.ex_date <= '2007-7-22' AND userid =
> 572
>
> The result should be 1573, but... it is always 1. here is the code in
> context...
>
> $db2->query("SELECT sum(transaction.deposit) -
> sum(transaction.withdraw)
> AS balance FROM transaction WHERE transaction.ex_date <= '$process_date'
> AND
> userid = $userid");
> $cur_balance = $db2->next_record();
> $new_balance = $cur_balance + ($process_rate*$cur_balance);
> echo "Cur bal: \$$cur_balance<br>";
>
> I did originally have $cur_balance = $db2->query("select...... and I
> expected
> to have the value as $cur_balance.
>
> Some help would be greatly appreciated.
>
> Thanks
>
> david
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
idh63
Posts: 76
|
| Posted: 01/24/2008, 1:26 PM |
|
hi Don,
Thanks again for the help.
I did realize that i needed $db2->f("balance"), but i always ended up with an empty value.
finally i tried $db2->f([0]) and that did the trick.
Regards
David
Quote DonB:
$cur_balance = $db2->next_record();
doesn't return the VALUE, it returns a resource id. The value is
$db2->f("balance").
--
DonB
|
 |
 |
|