Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
php calculate variable from query
Old 01-14-2011, 11:40 AM php calculate variable from query
Experienced Talker

Posts: 43
Trades: 0
Ok i got a stupid little problem.
I need to calculate a variable from a sql query.
I can echo a variable from the query and it shows for example 22, but i need to multiply it.

So i got:
Code:
$old = $query[nValue]; 
echo $old;
it works it shows 20

Code:
$old = $query[nValue]; 
$percent = 2;
$multip =  $old * $percent;

echo $multip;
it doens't work and shows 0.

Or:
Code:
$multip =  $query[nValue] * 2;
echo $multip;
This shows 2??, so please some php guru can explain me why this doesn't work?

Last edited by TheSir; 01-14-2011 at 11:42 AM..
TheSir is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-14-2011, 01:11 PM Re: php calculate variable from query
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
The value nValue is being suggested as a constant without the quotes and I think that is what is messing things up.

echo $query['nValue'] * 2;
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 01-14-2011, 02:25 PM Re: php calculate variable from query
Experienced Talker

Posts: 43
Trades: 0
No effect, same results.
Thnx for replying though!
TheSir is offline
Reply With Quote
View Public Profile
 
Old 01-14-2011, 02:46 PM Re: php calculate variable from query
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
The only thing I can think of is dumping $query:
PHP Code:
print_r($query); 
Maybe that will yield some insight into what the issue is.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 01-14-2011, 04:43 PM Re: php calculate variable from query
Experienced Talker

Posts: 43
Trades: 0
Hell yeah i figured it out, variable was placed in wrong part needit to place it in the while loop itself for some reason.

Pretty stupid and weird but ok it works now. This can be closed.
TheSir is offline
Reply With Quote
View Public Profile
 
Old 01-14-2011, 05:44 PM Re: php calculate variable from query
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Probably a good time to point out that posting more than the code you think isn't working is always better for debugging.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to php calculate variable from query
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.22712 seconds with 12 queries