Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)
Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki
I am looking to compare for a blank file, but as I am anything but proficient in PHP, I am not sure how to code a compare looking at a field to see if it is blank and if it isn't display it.
What I am trying to do is:
<?php
if ($wx[field]<>"") // is the $wx[field] blank?
echo $wx[field]; // If not, display it
}
?>
I have been trying to find the correct to do the above, but everything I find on the subject is comparing for numeric value comparisons, not text comparisons. I could use some advice from a more skilled PHP coder than me. which isn't saying a lot for me.
The best test may depend on what you expect to find in the variable.
There are differences between =, == and ===
This table may be of interest;
isset is_null ===null ==null empty
null | F | T | T | T | T |
unset | F | T | T | T | T |
"" | T | F | F | T | T |
[] | T | F | F | T | T |
0 | T | F | F | T | T |
false | T | F | F | T | T |
true | T | F | F | F | F |
1 | T | F | F | F | F |
\0 | T | F | F | F | F |
Note all the 'unexpected?' T results for isset.
Check these with a query on the internet for php isset and/or php null or similar to get the full explanation.
I would suggest the use of the PHP function 'empty()' rather than 'isset()' as, not only does it check if the variable is false (or empty), it also checks if the variable exists - the function 'empty()' does not generate a warning if the variable does not exist.
if ( empty ( $wx[field] )) {
// display a message indicating the variable is empty
}
else {
echo $wx[field]; // if the variable in not empty
}
Note: The following things/values are considered to be empty:
"" (an empty string)
•0 (0 as an integer)
•0.0 (0 as a float)
•"0" (0 as a string)
•NULL
•FALSE
•array() (an empty array)
•$var; (a variable declared, but without a value)
What I am trying to do is make use of the field "currcond" generated by Cumulus' software. It is the field you can enter in some comment like "Today is supposed to be a really nice day!" and it will be displayed on whatever page you put in the pointer to is. For example I am putting it in my index.php page (Saratoga templates).
If I do the following, no problems at all except when I leave the line in the Cumulus page blank, then it displays a blank line.
aznetcowboy wrote:.....
If I do the following, no problems at all except when I leave the line in the Cumulus page blank, then it displays a blank line.
<body>
<?php
############################################################################
include("header.php");
############################################################################
include("menubar.php");
############################################################################
//
$useTopWarning = true; // set to true to use only the rss-top-warning script
// set to false to use the rss-advisory script instead
?>
<div id="main-copy">
<?php // insert desired warning box at top of page
if(isset($SITE['NWSalertsCodes']) and count($SITE['NWSalertsCodes']) > 0) {
// Add nws-alerts alert box cache file
include_once("nws-alerts-config.php");
include($cacheFileDir.$aboxFileName);
// Insert nws-alerts alert box
echo $alertBox;
?>
<script type="text/javascript" src="nws-alertmap.js"></script>
<?php
} else { // use atom scripts of choice
if ($useTopWarning) {
include_once("atom-top-warning.php");
} else {
print " <div class=\"advisoryBox\">\n";
$_REQUEST['inc'] = 'y';
$_REQUEST['summary'] = 'Y';
include_once("atom-advisory.php");
print " </div>\n";
}
}
?>
<div class="column-dark">
<div align="center">
<?php echo $WX['currcond']?> <!-- THIS CODE WORKS -->
<?php
echo ($wx['currcond'] ? $wx['currcond'] : ""); // THIS CODE DOES NOT WORK //
?>
<table width="100%" style="border: none">
<tr><td align="center">
<img src="http://icons.wunderground.com/data/640x480/<?php echo $SITE['WUregion']; ?>_rd_anim.gif" alt="Regional Radar" width="320" height="240" style="margin: 0px; padding: 0px; border: none" />
</td>
<td align="center">
<img src="http://icons.wunderground.com/data/640x480/<?php echo $SITE['WUregion']; ?>_ir_anim.gif" alt="Regional Infrared Satellite"
width="320" height="240" style="margin: 0px; padding: 0px; border: none" />
</td>
</tr>
<tr><td colspan="2" align="center"><small>Radar/Satellite images courtesy of <a href="http://www.weatherunderground.com">Weather Underground</a>.</small></td></tr>
</table>
<img src="<?php echo $SITE['imagesDir']; ?>spacer.gif" alt="spacer"
height="2" width="620" style="padding:0; margin:0; border: none" />
<div align="center">
<?php if(isset($SITE['ajaxDashboard']) and file_exists($SITE['ajaxDashboard']))
{ include_once($SITE['ajaxDashboard']);
} else {
print "<p> </p>\n";
print "<p> </p>\n";
print "<p>Note: ajax-dashboard not included since weather station not yet specified.</p>\n";
for ($i=0;$i<5;$i++) { print "<p> </p>\n"; }
}?>
The line where I have <!-- THIS CODE WORKS --> is what will display something when there is a non-space value in $wx[currcond] or a blank line if $wx[currcond] is blank! Where I have // THIS CODE DOES NOT WORK // displays nothing, period. I'm hoping this code can give a better picture of what I am talking about.
Thanks a bunch! That was the problem. It was right in front of my nose, but too obvious I guess.
Changing echo ($wx['currcond'] ? $wx['currcond'] : "")
to echo ($WX['currcond'] ? $WX['currcond'] : "")
made all the difference. Thanks again for seeing this!