0

XML ファイルから取得した別の変数から値を取得するこのコードがあります。これは現在、コードをクリーンアップする前に機能していましたが、なぜ機能しないのかわかりません。どのように機能すると想定されているかは、変数を取得し、その変数の値に基づいて色を作成することです。次に、この場合は $stormScale という新しい変数を取得し、それを CSS クラスに割り当てて、セルの色をこのように表示します。

$td4Style = "{$sbrdr}; {$bbrdr}; padding: 2px 6px 6px 6px; background-color:{$stormScale};";

次に、そのクラスを取得し、他のデータのテーブルがこのように出力されるときに使用します。

$tData .= "  <tr><td style='{$td4Style}'>&nbsp;</td></tr>\n";

このスイッチは、値に基づいて色を割り当てると想定されていますが、現在は機能していません。なぜ、何が欠けているのかわかりません。

$stormScale = '';

           switch($ef)
{
              case '0':
                    $stormScale = 'rgba(0, 255, 255, 0.2)';
                             break;
              case '1':
                    $stormScale = 'rgba(0, 0, 255, 0.1)';
                             break;
              case '2':
                    $stormScale = 'rgba(0, 255, 0, 0.2)';
                             break;
              case '3':
                    $stormScale = 'rgba(255, 255, 0, 0.1)';
                             break;
              case '4':
                    $stormScale = 'rgba(255, 153, 51, 0.2)';
                             break;
              case '5':
                    $stormScale = 'rgba(255, 0, 0, 0.2)';
                             break;

}

これが完全なコードです。十分な情報を提供できたことを願っています。私は何が欠けていますか?

<?php 
#######################################################################################
#
#  GOOGLE MAPS V3 KILLER TORNADOS
#  version 1.00
#
#  This program is free and no license is required.
#  
#
#  mesquiteweather.net
#
#######################################################################################

////  SETTINGS  ////

$GKey = 'ENTER_YOUR_KEY';                    // Enter your Google Maps API Key
$GImage = 'images/watermark_MW_GMap.png';     // Path to your watermark for your Google Map

// Change colors
$bc        = 'True';     // If True cell tables will show color of EF scale, set to false to use CSS style color
$dtColor   = '#FFF';     // Ttile Color  Examples:   "#FC0"   "#FFCC00"   "white"

////  END OF SETTINGS  ////

#######################################################################################

ini_set('display_errors','1');

// overrides from the Carter Lake Settings.php file (if applicable)
global $SITE;
if(isset($SITE['cacheFileDir'])) {$cacheFileDir = $SITE['cacheFileDir']; }
if (isset($SITE['imagesDir']))   {$imagesDir = $SITE['imagesDir'];}
if(isset ($SITE['tz']))          {$ourTZ = $SITE['tz'];}
if(!function_exists('date_default_timezone_set'))
{
    putenv("TZ=" . $ourTZ);
}
else
{
    date_default_timezone_set("$ourTZ");
}

// get path info & protect for cross-site scripting vulnerability
$sri = ($_SERVER['REQUEST_URI']) ? str_replace('#SA', '', htmlspecialchars(strip_tags($_SERVER['REQUEST_URI']))) : '';

//Set path to data file
$data = "http://www.spc.noaa.gov/climo/torn/xml/2013.xml";

$bbrdr = 'border-bottom:thin solid black';       // bottom
$lbrdr = 'border-left:thin solid black';         // left
$rbrdr = 'border-right:thin solid black';        // right
$tbrdr = 'border-top:thin solid black';          // top
$sbrdr = 'border-right:thin solid black; '.
         'border-left:thin solid black';         // side
$tableStyle = "width: 100%; margin:0px auto; background-color:{$bkgColor};";
$td1Style = "{$tbrdr};{$sbrdr}; padding:2px 0px 2px 6px;  background-image:url({$imagesDir}headerbgd2.gif); color:{$dtColor};";
$td2Style = "{$sbrdr}; padding:6px 0px 0px 6px; background-color:{$stormScale};";
$td3Style = "{$sbrdr}; line-height:5px; background-color:{$stormScale};";
$td4Style = "{$sbrdr}; {$bbrdr}; padding: 2px 6px 6px 6px; background-color:{$stormScale};";

//Define table to display after each storm report
$afterTable = "<table style='margin-bottom: 10px;' border='0' cellpadding='0' cellspacing='0' width='100%'><tbody><tr><td><img alt='' src='images/1pixel.gif' border='0' height='7' width='7'></td><td class='shadow-mid' width='100%'><img alt='' src='images/1pixel.gif' border='0' height='7' width='7'></td><td><img alt='' src='images/1pixel.gif' border='0' height='7' width='7'></td></tr><tbody></table>\n";


// Lets parse the XML feed
$xml = simplexml_load_file($data);

//Set initial output to false
    $tData = false;
foreach($xml->fatalities as $fatalities){

    $yrnum = $fatalities['yrnum'];
    $dt = $fatalities['dt'];
    $time = $fatalities['time'];
    $updateTime = DATE("g:i a", STRTOTIME($time));
    $tz = $fatalities['tz'];
    $ef = $fatalities['ef'];
    $location = $fatalities['location'];
    $state = $fatalities['st'];
    $watch = $fatalities['watch'];
    $watchn = str_replace("WT","WW","$watch");
    $deaths = $fatalities['deaths'];

  $stormScale = '';

           switch($ef)
{
              case '0':
                    $stormScale = 'rgba(0, 255, 255, 0.2)';
                             break;
              case '1':
                    $stormScale = 'rgba(0, 0, 255, 0.1)';
                             break;
              case '2':
                    $stormScale = 'rgba(0, 255, 0, 0.2)';
                             break;
              case '3':
                    $stormScale = 'rgba(255, 255, 0, 0.1)';
                             break;
              case '4':
                    $stormScale = 'rgba(255, 153, 51, 0.2)';
                             break;
              case '5':
                    $stormScale = 'rgba(255, 0, 0, 0.2)';
                             break;

}



 // construct data for table display
    $tData .= "<table style='{$tableStyle}' cellpadding='0' cellspacing='0'>\n";
    $tData .= "<tbody>\n";
    $tData .= "  <tr><td style='{$td1Style}'><b>2013 Killer Tornado #{$yrnum}</b></td></tr>\n";
    $tData .= "  <tr>\n";
    $tData .= "    <td style='{$td2Style}'>Date: <b>{$dt}</b>&nbsp;&nbsp; - &nbsp;&nbsp;</b>Time: <b>{$updateTime}</b>&nbsp;&nbsp; - &nbsp;&nbsp;</b>EF: <b>{$ef}</b>&nbsp;&nbsp; - &nbsp;&nbsp;</             b>Fatalities: <b>{$deaths}</b>&nbsp;&nbsp; - &nbsp;&nbsp;Watch Issued: {$watchn}<b></a></td>\n";
    $tData .= "  </tr>\n";
    $tData .= "  <tr><td style='{$td3Style}'>&nbsp;</td></tr>\n";
    $tData .= "  <tr><td style='{$td4Style}'>County: <b>{$location}</b>&nbsp;&nbsp; - &nbsp;&nbsp;State: <b>{$state}</b></td></tr>\n";
    $tData .= "</tbody>\n";
    $tData .= "</table>\n";
    $tData .=  $afterTable;

 }  

?>

<?php print $tData ?>

-ありがとう

4

2 に答える 2