Heya folks,
In this example {co2} is a value returned from a webservice submitted via chronoform and stored in mysql. It may be blank, null, 0, or a positive number (i.e. 405). Theres very little data integrety but I have to use it!
I am looking to display a bullet within the chonoconnectivty body only if it is a positive number returned.
As such, I assume that if empty() would be the best conditional to use ? As such I have this test code.
When I replace $var = '0'; with '405', '' or 'NULL' I can see that it works as intended. i.e. With $var set to 0 I get 'No CO2 Value' and with 405 I get '405 CO2'.
However when I use $var = '{co2}'; - {co2} is always interpreted as NOT empty, however, my echo of {var} shows the correct value. (even when {co2} is 0).
I tink this should be somthing simple, can anyone steer me in the correct direction ?
Cheers,
Mizpah
In this example {co2} is a value returned from a webservice submitted via chronoform and stored in mysql. It may be blank, null, 0, or a positive number (i.e. 405). Theres very little data integrety but I have to use it!
I am looking to display a bullet within the chonoconnectivty body only if it is a positive number returned.
As such, I assume that if empty() would be the best conditional to use ? As such I have this test code.
<?php
$var = '0';
if (empty($var)){
echo '<li style="padding 0;">No CO2 Value</li>';
}else{
echo '<li style="padding 0;">{co2} CO2</li>';
}
echo $var;
?>
When I replace $var = '0'; with '405', '' or 'NULL' I can see that it works as intended. i.e. With $var set to 0 I get 'No CO2 Value' and with 405 I get '405 CO2'.
However when I use $var = '{co2}'; - {co2} is always interpreted as NOT empty, however, my echo of {var} shows the correct value. (even when {co2} is 0).
I tink this should be somthing simple, can anyone steer me in the correct direction ?
Cheers,
Mizpah
Heya Greyhead!
Thanks for the responce, and I see the logic, but its not quite behaving!
It now reads;
Now whatever I do I get 'NO CO2 VALUE'. Ive stuck and echo in and the correct value for {co2} is being produced!
I had thought it was somthing to do with '$var = {co2};' not being recognised as the correct datatype ?
However when I changed it to '30' as a test manually, it still reports no value!
Now unless im much mistaken, last time I checked 30 is a number and greater than 0!! (I know its late, but its not that late!)
Ive also checked the mysql database, and the field type is set to 'INT'.
Am currently still stumped🙂
Thanks for the responce, and I see the logic, but its not quite behaving!
It now reads;
<?php
$co2 = '{co2}';
echo $co2;
if (is_int($co2) && $co2 > 0 ){
echo '<li style="padding 0;">{co2} CO2</li>';
}else{
echo '<li style="padding 0;">NO CO2 VALUE</li>';
}
?>
Now whatever I do I get 'NO CO2 VALUE'. Ive stuck and echo in and the correct value for {co2} is being produced!
I had thought it was somthing to do with '$var = {co2};' not being recognised as the correct datatype ?
However when I changed it to '30' as a test manually, it still reports no value!
Now unless im much mistaken, last time I checked 30 is a number and greater than 0!! (I know its late, but its not that late!)
Ive also checked the mysql database, and the field type is set to 'INT'.
Am currently still stumped🙂
Hi Mizpah,
Ah we're in ChronoConnectivity - apologies for not noticing (I must color code the forums or something).
There was a post about this just a few days ago. If I remember correctly; the order in which ChronoConnectivity evaluates the PHP and the variables measn that PHP doesn't see the variable. Use $MyRow->co2 instead of {co2} and see if that works.
Bob
Ah we're in ChronoConnectivity - apologies for not noticing (I must color code the forums or something).
There was a post about this just a few days ago. If I remember correctly; the order in which ChronoConnectivity evaluates the PHP and the variables measn that PHP doesn't see the variable. Use $MyRow->co2 instead of {co2} and see if that works.
Bob
Thanks Grey!
That of course did it, for anyone else reviewing the thread, heres the final snippet;
Note that I left the true condition blank to display no bullet at all, and went back to the statement 'blank' after I was evaluating the $var correctly! I have of course renamed $var since as well! For some reason even though the value in the DB is 'int' it keeps failing the is_int conditional, possibly the array type - not an issue however!
That of course did it, for anyone else reviewing the thread, heres the final snippet;
<?php
$var = $MyRow->co2;
if (empty($var)){
}else{
echo '<li style="padding 0;">{co2} CO2</li>';
}
?>
Note that I left the true condition blank to display no bullet at all, and went back to the statement 'blank' after I was evaluating the $var correctly! I have of course renamed $var since as well! For some reason even though the value in the DB is 'int' it keeps failing the is_int conditional, possibly the array type - not an issue however!
This topic is locked and no more replies can be posted.