Forums

calculation with DB-fields - integer issue

bobmijwaard 17 Apr, 2009
I am trying to make a CO2 compensation calculation for one of my customers.
The user fills in some fields (gas , electricity) and this data is stored in a DB-table. I have given the fields data-type int(11), but also tried smallint.

With chronoconnectivity I try to do the calculation. Below is just a try:

Body Field:
<?php
$value1 = 111;
$gas= '{gas}';
$result = $value1 - $gas;
echo  "compesnsation gas " .$result. " ton CO2   ";
echo "<br>\n";
echo "added value gas: " .$gas. " m3";

echo "<br>\n";
if (is_int($gas)) {
 echo "is integer\n";
} else {
 echo "is not an integer\n";
}

?>


Result:
compesnsation gas 111 ton CO2
added value gas: 0 m3
is not an integer

Value1 = just a value to try
$gas= '{gas}'; to retrieve the data from the DB

The calculation always the result 111 whatever value of gas is used. the field gas is not handled as a integer field. The is_int function proves that.

Any one an idea?
GreyHead 17 Apr, 2009
Hi bobmijward,

Try $gas = intval( {gas} ); with no quotes.

Bob
bobmijwaard 17 Apr, 2009

Hi bobmijward,

Try $gas = intval( {gas} ); with no quotes.

Bob




Got the error:
PHP Parse error: parse error, expecting `')'' in E:\mijwaard.nl\wwwroot\umoja\components\com_chronoconnectivity\chronoconnectivity.html.php(176) : eval()'d code on line 4

Tried $gas = intval(' {gas}' );

with no success as well
GreyHead 17 Apr, 2009
Hi bobmijwaard,

One more . . .
$gas =& $row->gas;

Bob
bobmijwaard 17 Apr, 2009
Thanks a lot Bob,

This one works !!

Regards

Bob M.
GreyHead 17 Apr, 2009
Hi bobmijwaard,

Excellent - ChronoConnectivity keeps the database results in the $row object so you should be able to get any results from there. (Note that the object name may chang in a future release as $row is used in too many places.)

Bob
bobmijwaard 19 Apr, 2009

Hi bobmijwaard,

One more . . .

$gas =& $row->gas;

Bob



Where on the site (or elsewhere) can I find a overview of all available functions in ChronoConnectivity?
GreyHead 19 Apr, 2009
Hi bobmijwaard,

I'm afraid that you can't. Short of borrwoing Max's head or digging into the code (which is what I did to find this).

One day I'll get to understand it well enough to write some tutorials, but I haven't found the time yet.

Bob
bobmijwaard 19 Apr, 2009

Hi bobmijwaard,

I'm afraid that you can't. Short of borrwoing Max's head or digging into the code (which is what I did to find this).

One day I'll get to understand it well enough to write some tutorials, but I haven't found the time yet.

Bob



[off topic]
If you answer all questions as quick as you do mine and stay all day and night on this forum, you will not be able to find any time I'm afraid. 😀
I wonder how you find some time to eat and sleep!!
Meanwhile I go further into digging PHP and Chronoforms, besides doing some mod work on the Dutch Joomla forum.
[/off topic]
This topic is locked and no more replies can be posted.