CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Mysql5 php5 query result problem

Print topic Send  topic

Author Message
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
View profile  Send private message
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
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.