Jump to content

Texan78

Members
  • Posts

    272
  • Joined

  • Last visited

Posts posted by Texan78

  1. There is no format that way, it just prints the raw data. That works for one single entry if you're not wrapping it in a table for data yes, but there will be multiple entries. This is just a test XML file with one entry to test and setup the script.

     

    The variables are used in a table like so.

    // construct data for table display
        $tData .= "<table style='{$tableStyle}' cellpadding='0' cellspacing='0'>\n";
        $tData .= "<tbody>\n";
        $tData .= "  <tr><td style='{$td1Style}'><b>{$report}</b></td></tr>\n";
        $tData .= "  <tr>\n";
        $tData .= "    <td style='{$td2Style}'>Reported By: <b>{$fname} {$lname}</b>   -   </b>Location: <b>{$location}</b></td>\n";
        $tData .= "  </tr>\n";
        $tData .= "  <tr><td style='{$td3Style}'> </td></tr>\n";
        $tData .= "  <tr><td style='{$td4Style}'>Description: <b>{$description}</b></td></tr>\n";
        $tData .= "</tbody>\n";
        $tData .= "</table>\n";
        $tData .=  $afterTable;
    
    
  2. I am trying to parse an XML file which I have done many times but for some reason I am getting no output. Even when I try to echo a variable to test I get nothing.

     

    Here is the test XML file I am using. Now it may be possible the XML is not formatted correctly but it should be.

     

    http://www.mesquiteweather.net/xml/mesquite.xml

     

     

    Here is the snippet to parse the XML

    //Set path to data file
    $data = "http://www.mesquiteweather.net/xml/mesquite.xml";
    
    // Lets parse the XML feed
    $xml = simplexml_load_file($data);
    
    //Set initial output to false
        $tData = false;
    foreach($xml->entry as $entry){
    
        $fname = $entry->fname;
        $lname = $entry->lname;
        $location = $entry->location;
        $report = $entry->report;
        $description = $entry->description;
    
    // Set table style
       $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:{$reportColor};";
       $td3Style = "{$sbrdr}; line-height:5px; background-color:{$reportColor};";
       $td4Style = "{$sbrdr}; {$bbrdr}; padding: 2px 6px 6px 6px; background-color:{$reportColor};";
    
    
     // construct data for table display
        $tData .= "<table style='{$tableStyle}' cellpadding='0' cellspacing='0'>\n";
        $tData .= "<tbody>\n";
        $tData .= "  <tr><td style='{$td1Style}'><b>{$report}</b></td></tr>\n";
        $tData .= "  <tr>\n";
        $tData .= "    <td style='{$td2Style}'>Reported By: <b>{$fname} {$lname}</b>   -   </b>Location: <b>{$location}</b></td>\n";
        $tData .= "  </tr>\n";
        $tData .= "  <tr><td style='{$td3Style}'> </td></tr>\n";
        $tData .= "  <tr><td style='{$td4Style}'>Description: <b>{$description}</b></td></tr>\n";
        $tData .= "</tbody>\n";
        $tData .= "</table>\n";
        $tData .=  $afterTable;
    
     }
    
    //If no storms were in the source, set no storm message
    if(!$tData)
    {
        $tData = $noStormMessage;
    }
    
    echo $tData;
    
    ?>

    Here is the full code

    <?php
    #######################################################################################
    #
    #  SPOTTER NETWORK STORM REPORTS
    #  version 1.00
    #
    #  This program is free and no license is required.
    #
    #
    #  mesquiteweather.net
    #
    #######################################################################################
    
    ////  SETTINGS  ////
    
    
    ////  SETTINGS  ////
    
    $bkgColor                                       = '#d4d4d4';  // Background color   Examples:  "gray"  "#CCC"   "#CCCCCC"
    $bc                                             = '#EEEEEE';  // Background color of table cells
    $dtColor                                        = '#FFF';     // Date & time color  Examples:   "#FC0"   "#FFCC00"   "white"
    $width                                          = '100%';     // Set the width of the report tables
    
    ////  END OF SETTINGS  ////
    
    
    #######################################################################################
    
    ini_set('display_errors','1');
    
    ## Start Configurable data ##
    
    //Set path to data file
    $data = "http://www.mesquiteweather.net/xml/mesquite.xml";
    
    ## End Configurable data ##
    
    // 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 borders
       $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
    
    //Define table to display after each storm report
    $afterTable = "<table style='margin-bottom: 5px;' 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";
    
    // Let's assign the table some styles
       $noMessageStyle                              = "width:{$width}; text-align:center; 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;";
       $td3Style                                    = "{$sbrdr}; line-height:5px;";
       $td4Style                                    = "{$sbrdr}; {$bbrdr}; padding: 2px 6px 6px 6px;";
    
    
    //Set message to display if there were not report
        $noStormMessage                                     .= "<table style='{$noMessageStyle}' cellpadding='0' cellspacing='0'>\n";
        $noStormMessage                                     .= "<tbody>\n";
        $noStormMessage                                     .= "  <tr><td style='{$td1Style}'>LIVE STORM REPORTS</td></tr>\n";
        $noStormMessage                                     .= "  <tr><td style='{$td4Style}'>There are currently no storm reports for Mesquite</td></tr>\n";
        $noStormMessage                                     .= "</tbody>\n";
        $noStormMessage                                     .= "</table>\n";
        $noStormMessage                                     .= $afterTable;
    
    // Lets parse the XML feed
    $xml = simplexml_load_file($data);
    
    //Set initial output to false
        $tData = false;
    foreach($xml->entry as $entry){
    
        $fname = $entry->fname;
        $lname = $entry->lname;
        $location = $entry->location;
        $report = $entry->report;
        $description = $entry->description;
    
    // Set table style
       $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:{$reportColor};";
       $td3Style = "{$sbrdr}; line-height:5px; background-color:{$reportColor};";
       $td4Style = "{$sbrdr}; {$bbrdr}; padding: 2px 6px 6px 6px; background-color:{$reportColor};";
    
    
     // construct data for table display
        $tData .= "<table style='{$tableStyle}' cellpadding='0' cellspacing='0'>\n";
        $tData .= "<tbody>\n";
        $tData .= "  <tr><td style='{$td1Style}'><b>{$report}</b></td></tr>\n";
        $tData .= "  <tr>\n";
        $tData .= "    <td style='{$td2Style}'>Reported By: <b>{$fname} {$lname}</b>   -   </b>Location: <b>{$location}</b></td>\n";
        $tData .= "  </tr>\n";
        $tData .= "  <tr><td style='{$td3Style}'> </td></tr>\n";
        $tData .= "  <tr><td style='{$td4Style}'>Description: <b>{$description}</b></td></tr>\n";
        $tData .= "</tbody>\n";
        $tData .= "</table>\n";
        $tData .=  $afterTable;
    
     }
    
    //If no storms were in the source, set no storm message
    if(!$tData)
    {
        $tData = $noStormMessage;
    }
    
    echo $tData;
    
    ?>
    

    What am I missing or overlooking?

     

    -Thanks

  3. Hello, I have a script that displays data from a XML file into a table and it works great. What I want to do is try to set a background color to a table cell based on the report element it gets from the XML file. I have another script I have done this for and it works great. For some reason I can't seem to get it working with this script.

     

    Here is a working page of what it should look like. If you look below the map the tables have different backgrounds depending on the report.

     

    http://www.mesquiteweather.net/wxsvr.php

     

     

    Here is the actual page I am trying to get it to work on and the code I am using below.

     

    http://www.mesquiteweather.net/wxspotter.php

    <?php
    #######################################################################################
    #
    #  SPOTTER NETWORK STORM REPORTS
    #  version 1.00
    #
    #  This program is free and no license is required.
    #
    #
    #  mesquiteweather.net
    #
    #######################################################################################
    
    ////  SETTINGS  ////
    
    
    ////  SETTINGS  ////
    
    $bkgColor                                       = '#d4d4d4';  // Background color   Examples:  "gray"  "#CCC"   "#CCCCCC"
    $bc                                             = '#EEEEEE';  // Background color of table cells
    $dtColor                                        = '#FFF';     // Date & time color  Examples:   "#FC0"   "#FFCC00"   "white"
    $width                                          = '100%';     // Set the width of the report tables
    
    ////  END OF SETTINGS  ////
    
    
    #######################################################################################
    
    ini_set('display_errors','1');
    
    ## Start Configurable data ##
    
    //Set path to data file
    $data = "http://www.spotternetwork.org/data.php";
    
    ## End Configurable data ##
    
    // 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 borders
       $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
    
    //Define table to display after each storm report
    $afterTable = "<table style='margin-bottom: 5px;' 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";
    
    // Let's assign the table some styles
       $noMessageStyle                              = "width:{$width}; text-align:center; 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;";
       $td3Style                                    = "{$sbrdr}; line-height:5px;";
       $td4Style                                    = "{$sbrdr}; {$bbrdr}; padding: 2px 6px 6px 6px;";
    
    
    //Set message to display if there were not report
        $noStormMessage                                     .= "<table style='{$noMessageStyle}' cellpadding='0' cellspacing='0'>\n";
        $noStormMessage                                     .= "<tbody>\n";
        $noStormMessage                                     .= "  <tr><td style='{$td1Style}'>LIVE STORM SPOTTER REPORTS</td></tr>\n";
        $noStormMessage                                     .= "  <tr><td style='{$td4Style}'>There are currently no storm reports</td></tr>\n";
        $noStormMessage                                     .= "</tbody>\n";
        $noStormMessage                                     .= "</table>\n";
        $noStormMessage                                     .= $afterTable;
    
    $xml = simplexml_load_file($data);
    
    //Set initial output to false
    $tData = false;
    foreach($xml->report as $report)
    {
        $date        = $report['stamp'];
        $time        = strtotime($date.'UTC');
        $dateInLocal = date("D g:i a", $time);
        $narrative   = $report['narrative'];
        $loc         = $report['city1'];
        $tz          = $report['tz'];
    
        $stormType = 'Unknown';
        foreach($report->attributes() as $typeKey => $id)
        {
            if($id == 1)
            {
                if(array_key_exists($typeKey, $stormTypesAry))
                {
                    $stormType = $stormTypesAry[$typeKey];
                }
                break;
            }
        }
    
        $stormTypesAry = array(
        'tornado' => 'Tornado',
        'funnelcloud' => 'Funnel Cloud',
        'wallcloud' => 'Wall Cloud',
        'rotation' => 'Rotation',
        'hail' => 'Hail',
        'wind' => 'Wind',
        'flood' => 'Flood',
        'flashflood' => 'Flash Flood'
    );
    
    $reportColor = '';
    
               switch($stormTypesAry)
    {
                  case 'Tornado':
                        $reportColor = 'rgba(128, 128, 128, 0.4)';
                                  break;
                  case 'Funnel Cloud':
                        $reportColor = 'rgba(255, 222, 173, 0.4)';
                                  break;
                  case 'Wall Cloud':
                        $reportColor = 'rgba(255, 20, 147, 0.4)';
                                  break;
                  case 'Rotation':
                        $reportColor = 'rgba(255, 228, 181, 0.4)';
                                  break;
                  case 'Hail':
                        $reportColor = 'rgba(255, 255, 0, 0.4)';
                                  break;
                  case 'Wind':
                        $reportColor = 'rgba(255, 0, 0, 0.4)';
                                  break;
                  case 'Flash Flood':
                        $reportColor = 'rgba(255, 165, 0, 0.4)';
    
    
    }
    
    // Set table style
       $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:{$reportColor};";
       $td3Style = "{$sbrdr}; line-height:5px; background-color:{$reportColor};";
       $td4Style = "{$sbrdr}; {$bbrdr}; padding: 2px 6px 6px 6px; background-color:{$reportColor};";
    
    
     // construct data for table display
        $tData .= "<table style='{$tableStyle}' cellpadding='0' cellspacing='0'>\n";
        $tData .= "<tbody>\n";
        $tData .= "  <tr><td style='{$td1Style}'><b>{$stormType}</b></td></tr>\n";
        $tData .= "  <tr>\n";
        $tData .= "    <td style='{$td2Style}'>Reported: <b>{$dateInLocal}</b>   -   </b>Location: <b>{$loc}</b></td>\n";
        $tData .= "  </tr>\n";
        $tData .= "  <tr><td style='{$td3Style}'> </td></tr>\n";
        $tData .= "  <tr><td style='{$td4Style}'>Description: <b>{$narrative}</b></td></tr>\n";
        $tData .= "</tbody>\n";
        $tData .= "</table>\n";
        $tData .=  $afterTable;
    
     }
    
    //If no storms were in the source, set no storm message
    if(!$tData)
    {
        $tData = $noStormMessage;
    }
    
    echo $tData;
    
    ?>
    

    It should take this code to assign the colors....

    $stormTypesAry = array(
        'tornado' => 'Tornado',
        'funnelcloud' => 'Funnel Cloud',
        'wallcloud' => 'Wall Cloud',
        'rotation' => 'Rotation',
        'hail' => 'Hail',
        'wind' => 'Wind',
        'flood' => 'Flood',
        'flashflood' => 'Flash Flood'
    );
    
    $reportColor = '';
    
               switch($stormTypesAry)
    {
                  case 'Tornado':
                        $reportColor = 'rgba(128, 128, 128, 0.4)';
                                  break;
                  case 'Funnel Cloud':
                        $reportColor = 'rgba(255, 222, 173, 0.4)';
                                  break;
                  case 'Wall Cloud':
                        $reportColor = 'rgba(255, 20, 147, 0.4)';
                                  break;
                  case 'Rotation':
                        $reportColor = 'rgba(255, 228, 181, 0.4)';
                                  break;
                  case 'Hail':
                        $reportColor = 'rgba(255, 255, 0, 0.4)';
                                  break;
                  case 'Wind':
                        $reportColor = 'rgba(255, 0, 0, 0.4)';
                                  break;
                  case 'Flash Flood':
                        $reportColor = 'rgba(255, 165, 0, 0.4)';
    
    
    }
    
    

    Then assign the table color style like so...

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

    What am I missing or overlooking?

     

    -Thanks

  4. Thanks, that works but it throws off the alignment. Least I know for reference what the issue was case it happens in the future. I knew it was something simple but I am still learning proper syntax. I was able to get it to work this way as well and it aligns the way I need it. Not sure if this is proper or not but, it works too for now. Still to be determined if not having it after the else statement is going to cause any issues.  

    <table style="margin: 0px auto;" border="0" width="80%">
         <tbody><tr><?php
      if ($useAQI) {  //  Show Air Quality Index - PLASE YOUR CODE IN PLACE OF THIS SECTION AND START HERE Removing the line above too!
    ?>
    <?php
    if ($realValue1 == "") {
      echo "";
    } else {
      echo "<td style=\"text-decoration: none; text-align: center;\"><span style=\"font-size:90%; \">Quality<br/>Index<sup>6</sup>:</span><span style=\"font-size: 150%; font-weight:bold;\"><br/>" .$realValue1."</span></td>";
    }
    if ($realValue1 == "") {
      echo "Data Not<br />Available</span><br /><br /><img src=\"./ajax-images/AQI0.jpg\" width=\"50\" height=\"50\" alt=\"Data Not Available\" />";
    }?>
    
         <td style="text-decoration: none; text-align: center;"><? echo getGraphic($realIndex1, $aqiLevels, $aqiGraphic, $imagesDir); ?></td>
    
    
           <td style="text-decoration: none; text-align: center;"><span style="font-size:85%;"><?php langtrans('Density'); ?>:<br />
            <?php echo $airdensity . " kg/m<sup>3</sup>" ?></span></td>
    
            </tr>
    <?php } // end $showAQI - PLASE YOUR CODE INPLACE OF THIS SECTION AND END HERE  ?></td>
         </tr>
        </tbody></table>
    
    
  5. Ok I have a small issue. I know it's because of my lack of php knowledge and it's a small mistake but I can't seem to see it.

     

    I am getting this error in Coda 2.0

     

    Parse error: parse error, expecting `','' or `';'' in - on line 216
    Errors parsing -

     

    Which is referring to this line of code. All I did was  add echo and wrap <td> tags around it and it starting throwing the error.

    echo "<td>"getGraphic($realIndex1, $aqiLevels, $aqiGraphic, $imagesDir)"</td>";
    

    Here is this complete little script that the line above is extracted from.

    <table style="margin: 0px auto;" border="0" width="80%">
         <tbody><tr><?php
      if ($useAQI) {  //  Show Air Quality Index - PLASE YOUR CODE IN PLACE OF THIS SECTION AND START HERE Removing the line above too!
    ?>
    <?php
    if ($realValue1 == "") {
      echo "";
    } else {
      echo "<td style=\"text-decoration: none; text-align: center;\"><span style=\"font-size:90%; \">Quality<br/>Index<sup>6</sup>:</span><span style=\"font-size: 150%; font-weight:bold;\"><br/>" .$realValue1."</span></td>";
    }
    if ($realValue1 == "") {
      echo "Data Not<br />Available</span><br /><br /><img src=\"./ajax-images/AQI0.jpg\" width=\"75\" height=\"75\" alt=\"Data Not Available\" />";
    } else {
     echo "<td>"getGraphic($realIndex1, $aqiLevels, $aqiGraphic, $imagesDir)"</td>";
    }
    ?>
           <td style="text-decoration: none; text-align: center;"><span style="font-size:85%;"><?php langtrans('Density'); ?>:<br />
            <?php echo $airdensity . " kg/m<sup>3</sup>" ?></span></td>
    
            </tr>
    <?php } // end $showAQI - PLASE YOUR CODE INPLACE OF THIS SECTION AND END HERE  ?></td>
         </tr>
        </tbody></table>
    

    What is it that I am not seeing?

     

    -Thanks

  6.  

    Try using these three lines instead of yours

        $result                                     = $entries->xpath("//item");
    
        foreach ($result as $entry):
            $title                                  = $entry->title;
            $description                            = $entry->description;
    
    

     

     

    Ah I see the difference. It doesn't use //prefix because the element isn't a namespace right? That's strange because I have used it that way before on elements that weren't namespaces. I had even tried it exactly how you had it but, it had the //prefix included. Guess it just depends on the way the XML is formatted? Well you learn something everyday. It works perfectly now. Thank you for your help.

  7.     $title = $item->title;
        $desc = $item->description;
    

    not

        $title = $item['title'];
        $desc = $item['description'];
    

    title and description are not attributes

     

     

    Thank you, I tried that suggestion but I am still getting nothing. I have tried it several other ways too and I get nothing.

    <?php
    #######################################################################################
    #
    #  SPC TORNADO/SEVERE THUNDERSTORM WATCHES
    #  version 1.00
    #
    #  This program is free and no license is required.
    #
    #
    #  mesquiteweather.net
    #
    #######################################################################################
    
    ////  SETTINGS  ////
    
    // Change colors
    $bkgColor                                       = '#d4d4d4';     // Background color   Examples:  "gray"  "#CCC"   "#CCCCCC"
    $bc                                             = '#EEEEEE';  // Background color of table cells
    $dtColor                                        = '#FFF';     // Date & time color  Examples:   "#FC0"   "#FFCC00"   "white"
    $width                                          = '100%';
    
    ////  END OF SETTINGS  ////
    
    #######################################################################################
    
    ini_set('display_errors','1');
    
    ## Start Configurable data ##
    
    //Set path to data file
    $data                                           = "xml/spcwwrss.xml";
    
    ## End Configurable data ##
    
    // 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 borders
    $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
    
    //Define table to display after each storm report
    $afterTable                                     = "<table style='margin-bottom: 5px;' 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";
    
    // Let's assign the table some styles
       $noMessageStyle                              = "width:{$width}; text-align:center; 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;";
       $td3Style                                    = "{$sbrdr}; line-height:5px;";
       $td4Style                                    = "{$sbrdr}; {$bbrdr}; padding: 2px 6px 6px 6px;";
    
    
    //Set message to display if there were not report
        $noStormMessage                                     .= "<table style='{$noMessageStyle}' cellpadding='0' cellspacing='0'>\n";
        $noStormMessage                                     .= "<tbody>\n";
        $noStormMessage                                     .= "  <tr><td style='{$td1Style}'>SPC TORNADO/SEVERE THUNDERSTORM WATCHES</td></tr>\n";
        $noStormMessage                                     .= "  <tr><td style='{$td4Style}'>There are currently no active severe thunderstorm or tornado watches</td></tr>\n";
        $noStormMessage                                     .= "</tbody>\n";
        $noStormMessage                                     .= "</table>\n";
        $noStormMessage                                     .= $afterTable;
    
    
    //Set initial output to false
    $tData                                          = false;
    $entries                                        = simplexml_load_file($data);
    if(count($entries)):
        //Registering NameSpace
        $entries->registerXPathNamespace('prefix', 'http://www.w3.org/2005/Atom');
        $result                                     = $entries->xpath("//prefix:item");
    
        foreach ($result as $entry):
            $title                                  = $item['title'];
            $description                            = $item['description'];
    
    // Let's assign the table some styles
       $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:{$alertColor};";
       $td3Style                                    = "{$sbrdr}; line-height:5px; background-color:{$alertColor};";
       $td4Style                                    = "{$sbrdr}; {$bbrdr}; padding: 2px 6px 6px 6px; background-color:{$alertColor};";
    
    // construct data for table display
        $tData                                     .= "<table style='{$tableStyle}' cellpadding='0' cellspacing='0'>\n";
        $tData                                     .= "<tbody>\n";
        $tData                                     .= "  <tr><td style='{$td1Style}'><b>{$title}</b></td></tr>\n";
        $tData                                     .= "  <tr>\n";
        $tData                                     .= "    <td style='{$td2Style}'> </td>\n";
        $tData                                     .= "  </tr>\n";
        $tData                                     .= "  <tr><td style='{$td3Style}'> </td></tr>\n";
        $tData                                     .= "  <tr><td style='{$td4Style}'>Issued For: <b>{$description}</b></td></tr>\n";
        $tData                                     .= "</tbody>\n";
        $tData                                     .= "</table>\n";
        $tData                                     .= $afterTable;
    
           endforeach;
    endif;
    
    //If no storms were in the source, set no storm message
    if(!$tData)
    {
        $tData                                      = $noStormMessage;
    }
    
    echo $tData;
    
    ?>
    

    Here is a link to the test XML I am using.

     

    http://www.mesquiteweather.net/xml/spcwwrss.xml

     

    What am I missing?

  8. Hi all

     

    I have a client who wants to upload a picture, generate a feed using xml which then parses to there website. Because im new to all of this I wondered does anyone know any good tutorials which will help me achieve this using PHP???

     

    I would be grateful of any one who can help me.

     

    Thanks

     

    Stuart

     

     

    I would recommend starting a new thread for your issue.

  9. So, let me get this strait. You expect me to try and read through your crappy code and tell you what is wrong.

     

    I didn't ask you to read through the entire code and critic it.  I am not denying it is not crappy but I am still learning and it's what works for me so I know and have a understanding of the logic. Once I know how it functions then I can go back and clean it up so I know how it works. If I break it that's ok because I know where and why it broke. I ask about a specific problem and you took the liberty to rewrite the entire code and that is very generous but, I did not ask you to do that. I don't learn anything from someone else just doing it and demeaning me in the process. It's obvious you are well knowledgeable about php. There is no reason to demean someone for their lack of knowledge. That is why forums are around for people to ask questions and get help. Not to have people write them code for free for them.

     

    But, you can't be bothered with reading through code I provide.

     

     

    I did read through it but if I don't know the logic behind it then it doesn't help me because I have no idea behind the logic or where to begin to debug it. Least with my crappy code if something happens then I have an idea where to look and have an idea how to address or ask for help to the certain issue. I have actually applied a lot of that code it to other scripts to clean them up. So to assume I didn't read or go through it and learn from it is an inaccurate assumption.

     

    Read the code and figure out what it is doing.

     

    That would be easy if I knew what I was looking at and what it was suppose to do don't ya think?

     

     

    I am providing free help on my own time. If you don't want the help that I provide, then I won't provide it.

     

    I didn't ask for you to rewrite the entire code. I ask a specific question. If you like to offer suggestions on how to do something a better way then I am open but, to tell me I have to do it this way or this way is the best way or because this is how you do it and then get hostile and demeaning like you're getting when I choose not to do that way is completely unreasonable. I am comfortable doing what works for me at the moment which helps me learn and understand things at my pace, not someone else's pace. Please respect that.

     

    If you didn't notice my last post I did study the code and figured out one my issues. Which came down to you moving the styles of my code that originally worked before which caused me more work for having to figure out why that was happening. Which is why I said it may be crappy code but it helps me have a understanding then I can go back and clean it up later. That's how I prefer to do it, because you don't that should not be a reason to demean me. That's your preference, not mine. But after all this I am back to square one to my original question and what I was trying to find out that still isn't working from the code you provided. So all you have done is cost me to do more work for things I wasn't even concerned with at the moment as it is just a concept and wasted time for one simple question that I still don't have resolved.

     

    -Thanks!

  10. I got it sorted, I was assigning variable before its creation. So I just moved the table styles after the switch and before the table was created and works perfectly now.

     

    Only issue I am having is the fail over message if no data is not displaying. If there is no data it just displays a blank table with no data.

     

    Mesquite%20Weather%20-%20No%20Data.png

     

    Here is the current code.

    <?php
    #######################################################################################
    #
    #  GOOGLE MAPS V3 STATEWIDE ALERTS
    #  version 1.00
    #
    #  This program is free and no license is required.
    #  
    #
    #  mesquiteweather.net
    #
    #######################################################################################
    
    ////  SETTINGS  ////
    
    $state     = 'Texas';     // Enter your state
    $loc       = 'tx';        // Put the the two letter abbrevation of your state
    
    // Change colors
    $bkgColor  = '#FFF';     // Background color   Examples:  "gray"  "#CCC"   "#CCCCCC"
    $bc        = '#EEEEEE';  // Background color of table cells
    $dtColor   = '#FFF';     // Date & time color  Examples:   "#FC0"   "#FFCC00"   "white"
    
    ////  END OF SETTINGS  ////
    
    #######################################################################################
    
    ini_set('display_errors','1');
    
    ## Start Configurable data ##
    
    //Set message to display if there were not report
    $noStormMessage = 'There are currently no active watches, warnings or advisories';
    
    //Set path to data file
    $data = "http://alerts.weather.gov/cap/".$loc.".php?x=1";
    
    ## End Configurable data ##
    
    // 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 borders
    $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
    
    //Define table to display after each storm report
    $afterTable = "<table style='margin-bottom: 5px;' 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";
    
    //Set initial output to false
    $tData = false;
    $entries = simplexml_load_file($data);
    if(count($entries)):
        //Registering NameSpace
        $entries->registerXPathNamespace('prefix', 'http://www.w3.org/2005/Atom');
        $result = $entries->xpath("//prefix:entry");
    
        foreach ($result as $entry):
            $event = $entry->children("cap", true)->event;
            $effective = $entry->children("cap", true)->effective;
            $expires = $entry->children("cap", true)->expires;
            $updateDate = date("D, M d, g:i a", strtotime($updated));	
            $effectiveDate = date("D, M d, g:i a", strtotime($effective));
            $expiresDate = date("D, M d, g:i a", strtotime($expires));
            $status = $entry->children("cap", true)->status;
            $severity = $entry->children("cap", true)->severity;
            $urgency = $entry->children("cap", true)->urgency;
            $area = $entry->children("cap", true)->areaDesc;
            
            $alertColor = '';
    
               switch($event)
    {
                  case 'Air Quality Alert':
                        $alertColor = 'rgba(128, 128, 128, 0.4)';
                                  break;
                  case 'Fire Weather Watch':
                        $alertColor = 'rgba(255, 222, 173, 0.4)';
                                  break;
                  case 'Red Flag Warning':
                        $alertColor = 'rgba(255, 20, 147, 0.4)';
                                  break;
                  case 'Special Weather Statement':
                        $alertColor = 'rgba(255, 228, 181, 0.4)';
                                  break;
                  case 'Severe Thunderstorm Warning':
                        $alertColor = 'rgba(255, 165, 0, 0.4)';
                                  break;
                  case 'Severe Thunderstorm Watch':
                        $alertColor = 'rgba(219, 112, 147, 0.4)';
                                  break;               
                  case 'Severe Weather Statement':
                        $alertColor = 'rgba(0, 255, 255, 0.4)';
                               
    }
    
    // Let's assign the table some styles
       $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:{$alertColor};";
       $td3Style = "{$sbrdr}; line-height:5px; background-color:{$alertColor};";
       $td4Style = "{$sbrdr}; {$bbrdr}; padding: 2px 6px 6px 6px; background-color:{$alertColor};";         
    
    // construct data for table display
        $tData .= "<table style='{$tableStyle}' cellpadding='0' cellspacing='0'>\n";
        $tData .= "<tbody>\n";
        $tData .= "  <tr><td style='{$td1Style}'><b>{$event}</b></td></tr>\n";
        $tData .= "  <tr>\n";
        $tData .= "    <td style='{$td2Style}'>Effective: <b>{$effectiveDate}</b>   -   Expires: <b>{$expiresDate}</b>   -   Status: <b>{$status}</b>   -   Severity: <b>{$severity}</b>   -   Urgency: <b>{$urgency}</b></td>\n";
        $tData .= "  </tr>\n";
        $tData .= "  <tr><td style='{$td3Style}'> </td></tr>\n";
        $tData .= "  <tr><td style='{$td4Style}'>Issued For: <b>{$area}</b></td></tr>\n";
        $tData .= "</tbody>\n";
        $tData .= "</table>\n";
        $tData .=  $afterTable;  
    
           endforeach;
    endif;
     
    //If no storms were in the source, set no storm message
    if(!$tData)
    {
        $tData = $noStormMessage;
    }
     
    echo $tData;
    
    ?>
    

    What am I missing and overlooking?

     

    -Thanks

  11. I think I must not be clear. Let me see if I can explain it a little better. I appreciate the help and suggestions. This is why I don't like having someone rewrite my entire code because I don't learn from it and if something doesn't work I have to wait and rely on forums instead of figuring it out myself. The original code wasn't final. It was just a concept.  It's a learning process that works for me.

     

    This is what I am having problems with that is now not currently working.

    $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;

    What that is suppose to do is take the value of that variable and assign a color to it.

     

    THEN the variable $stormScale is used as such to assign that color as a cell color based on the value and amended to the current class

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

    Then that classis applied to the HTML in the PHP.

     

    That's not my issue. I can sort out all the details for styling later and is not important to me right now as it appears to be correct.

     

     

    The issue is this loop isn't working now and it was working fine before with my original code. I hope that is a little clearer.

     

    -Thanks

  12. I have a script for a Google Map which works great. I have the code to the map in a seperate Js file which I call in the page where I want to display like this.

    <script src="https://maps.googleapis.com/maps/api/js?key=(GKey)&sensor=false"></script>
    <script type="text/javascript" src="gmap/util.js"></script>
    <script type="text/javascript" src="gmap/killerTornados.js"></script>

    the killerTornados.js is the file that contains the code for the map. Now I have made a var in the top of the file for settings. Which is called var GKey. That way when I share this script uses can set all their settings there.

     

    My question is how do I define the variable in the script include? In the URL below I have tried to define the var (GKey) like you do in the actual script but this does work this way like this. How do I properly define this?

    <script src="https://maps.googleapis.com/maps/api/js?key=(GKey)&sensor=false"></script>

    -Thanks

     

  13. Sorry, but creating clean, logical code from the beginning will reduce the total time to get your solution and reduce bugs. It take a little bit of extra time up front to do that, but you save much more time to actually complete since you are not going back and breaking things when you try to "clean up". So, I am not going to go back and rewrite the code into a less logical format.

     

    I agree and it looks so much nicer and I am a perfectionist, I am just not experienced enough to do it from the start as I am still learning. Since I am self teaching myself and you are searching the net looking for answers and reading tutorials and documents I find so many different ways to do things. So it's easier for me right now to just get a working concept then work on building from that to improve it. I won't always do it this way but it makes it easier for me to learn as I see the wrong and right ways and how things should be properly written.

     

     

     

    I see no reason why that bit of code would break your format since it was a copy/paste of the code you were already using. I just put it in a format that was programatically easier to work with. But, I do see that you had an HTML error in what you previously provided. That table that follows ever storm alert has an table OPENING tag at the end.

     

    Wow, I can't believe I missed that. It's never been a problem before so that may be why I have never noticed it. That fixed it, I completely overlooked the obvious.

     

    So if I could pick your brain one more time. I am cleaning up another code that is similar to this one but uses different data.

     

    I have this code that creates a background color for the table cells based on the value of one of the elements from the XML.

    $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;
                                 
    }

    How would I clean this up to a more efficient way? In my previous code it worked great but now it isn't working once I started cleaning up the script.

     

    It is defined here....

    $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};";

    Here is the complete full code.

    <?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>   -   </b>Time: <b>{$updateTime}</b>   -   </b>EF: <b>{$ef}</b>   -   </             b>Fatalities: <b>{$deaths}</b>   -   Watch Issued: {$watchn}<b></a></td>\n";
        $tData .= "  </tr>\n";
        $tData .= "  <tr><td style='{$td3Style}'> </td></tr>\n";
        $tData .= "  <tr><td style='{$td4Style}'>County: <b>{$location}</b>   -   State: <b>{$state}</b></td></tr>\n";
        $tData .= "</tbody>\n";
        $tData .= "</table>\n";
        $tData .=  $afterTable;
        
     }  
    
    ?>
    
    <?php print $tData ?>
    

    What could I do to improve that?

     

    -Thanks

     

     

     

     

  14.  

    This is a very odd use of the ternary operator

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

     

    I am creating this script for an open source template That was taken from the requirements of the template set. So it's not something I wrote or even paid much attention to.

     

     

    I'm seeing a lot of other inefficiencies as well. For example

    $attrs = array();
    foreach($report->attributes() as $a => $b) {
    $attrs[$a] = $b;
    }
    
    $value = array_search('1', $attrs);
    
    switch ($value) {
    
    

    That was based off an example I found. I am still novice at best so I am still learning. That was the code I was questioning.

     

     

    You are looping through all of the values in attributes and putting into an array, then searching the array for a particular value and only using that value. It doesn't appear you are using the other values.

     

    Well not all the attributes, just a few because those attributes are defined with a binary value to declare the selection. Instead of just one attribute that outputs the textual value. I.E. Instead of tornado="0" for no tornado or tornado="1" for tornado if that is the selection it should be just one attribute for something like weather="tornado" or weather="Hail" etc. That is not something I have control over that as that is how the person who has created the script to create the XML file I am getting the feed from has wrote it. I have an idea why it's done like that has those reports are generated from a form from users.

     

     

    Instead, just loop through attributes and "break;" the loop once you've found the value you want. Aslo, you can replace the switch with a simple array to convert the value to what you need.

     

    T

    hat actually is much better way and what I was looking for.

     

     

    Also, you could use classes for the default style properties to make the code cleaner. In fact, you should consider setting any "static" output as a variable outside the loop instead of redefining it inside the loop - such as the table that goes after each record. Makes it easier to manage the code. There are other things as well.

     

    Right now this is just a concept so I was just trying to get something working. Then I would go back and clean everything up as it is a way to help me learn and know how the code is put together.

     

    Here is a rewrite of your code that should display the "no storm" message depending on the format of the XML file (as Jessica alluded to). This isn't tested since I don't have your file. So, there may be some minor typos and such. But, I tried to put it in a more logical format. I would definitely use classes instead of creating all that code in the script.

     

    Thanks for the rewrite. It works but it breaks my layout out and since I don't know how this is pieced together I am having to take a step back to debug something I am not familiar with how it works. That is why I won't it the way it was so I had a working concept then go back and clean it up. That way I know how it works and I learn at the same time new things.

     

    This line is breaking my layout from the debugging I have been able to do. How to fix it I don't know.

    $afterTable = "<table style='margin-bottom: 5px;' 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";
    

    It is below the table output which is used as a table shadow when the table is constructed with this part.

    // construct data for table display
        $tData .= "<table style='{$tableStyle}' cellpadding='0' cellspacing='0'>\n";
        $tData .= "<tbody>\n";
        $tData .= "  <tr><td style='{$td1Style}'><b>{$stormType}</b></td></tr>\n";
        $tData .= "  <tr>\n";
        $tData .= "    <td style='{$td2Style}'>Reported: <b>{$dateInLocal}</b>   -   </b>Location: <b>{$loc}</b></td>\n";
        $tData .= "  </tr>\n";
        $tData .= "  <tr><td style='{$td3Style}'> </td></tr>\n";
        $tData .= "  <tr><td style='{$td4Style}'>Description: <b>{$narrative}</b></td></tr>\n";
        $tData .= "</tbody>\n";
        $tData .= "</table>\n";
        $tData .=  $afterTable;
    

    Please see the attached screen shots.

     

    This is how it should look, pay attention to the footer.

     

    Storm%20Spotter%20Network_Right.png

     

    This is how it looks with it breaking.

     

    Storm%20Spotter%20Network_Wrong.png

     

    Since I am not familiar with how this is constructed I am not sure how to fix this. That is why I like getting a working concept first that way I know how it is built when I go back to clean it up and if something isn't working I know what I did that caused the problem so I know what to target it and helps me learn the logic.

     

    Any suggestions why this is happening?

     

    -Thanks

     

     

  15. No data meaning what? If there's no data will $xml->report be null, 0, an empty array? Check the documentation.

    You'll have to figure out based on the XML document what qualifies as no data, and test for that.

     

    Thank you for the response. The XML feed is a feed of storm reports for a 3 hour span. If there is no reports currently then there is no data. I wasn't sure what the condition would be based off of to display the table if there was or wasn't data. I wasn't sure if it needed to based off the element report. That was the clarification I was looking for. 

     

    -Thanks

  16. I am trying to configure an else if statement but I am little stumped on what the condition should be. I have a script that is supplied with data from a parsed XML. The data is then passed to a table to display dynamically. As in it only shows tables for the data if there is data to be displayed. So what I am trying to do is show a different table when there is no data that says basically "There are no reports at this time". I am just not sure what the condition should be to display the data table and if there is no data then show the alternate table. 

     

    Here is the entire file. the $tdata is the one that shows the data. Then at the bottom you will see the print statement then I call this file with an include statement in another page to display.

    <?php 
    #######################################################################################
    #
    #  SPOTTER NETWORK STORM REPORTS
    #  version 1.00
    #
    #  This program is free and no license is required.
    #  
    #
    #  mesquiteweather.net
    #
    #######################################################################################
    
    ////  SETTINGS  ////
    
    
    // Change colors
    $bkgColor  = '#FFF';     // Background color   Examples:  "gray"  "#CCC"   "#CCCCCC"
    $bc        = '#EEEEEE';  // Background color of table cells
    $dtColor   = '#FFF';     // Date & time 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
    ($_SERVER['REQUEST_URI']) ? $sri = htmlspecialchars(strip_tags($_SERVER['REQUEST_URI'])) : $sri = '';
    $sri2 = str_replace('#SA', '', $sri);  // clean up for drop down menu
    
    // set borders
    $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
    
    $tData   = '';                                    // set variable
    $nothing = 'There are currently no storm reports';                                    // set variable
    $data = "http://www.spotternetwork.org/data.php";
    $xml = simplexml_load_file($data);
    
    foreach($xml->report as $report){
    
        $date = $report['stamp'];
        $narrative = $report['narrative'];
        $loc = $report['city1'];
        $tz = $report['tz'];
     
        $attrs = array();
                foreach($report->attributes() as $a => $b) {
        $attrs[$a] = $b;
    }
    
    $value = array_search('1', $attrs);
    
    switch ($value) {
        case 'tornado':
            echo "Tornado";
            break;
        case 'funnelcloud':
            echo "Funnel Cloud";
            break;
        case 'wallcloud':
            echo "Wall Cloud";
            break;
        case 'rotation':
            echo "Rotation";
            break; 
        case 'hail':
            echo "Hail";
            break; 
        case 'wind':
            echo "Wind";
            break;
        case 'flood':
            echo "Flood";
            break;  
        case 'flashflood':
            echo "Flash Flood";
                                 
    }   
            
        $time = strtotime($date.' UTC');
        $dateInLocal = date("D g:i a", $time);
        
                     
    // construct data for table display
      $tData .= '<table style="width: 100%; margin: 0px auto; background-color:<?php print ($bkgColor); ?>;" cellpadding="0" cellspacing="0">
     <tbody><tr>
      <td style="'.$tbrdr.';'.$sbrdr.'; padding: 2px 0px 2px 6px;  background-image:url('.$imagesDir.'headerbgd2.gif); color: '.$dtColor.'"><b>'.$string.'</b>
     </td>
     </tr>
     <tr>
      <td style="'.$sbrdr.'; padding: 6px 0px 0px 6px; background-color: '.$bc.';">Reported: <b>'.$dateInLocal.'</b>   -   </b>Location: <b>'.$loc.'</b></td>
     </tr>
     <tr>
      <td style="'.$sbrdr.'; line-height:5px; background-color:'.$bc.'"> </td>
     </tr>
     <tr>
      <td style="'.$sbrdr.'; '.$bbrdr.'; padding: 2px 6px 6px 6px; background-color:'.$bc.'">Description: <b>'.$narrative.'</b></td></tr></tbody></table>
    <table style="margin-bottom: 5px;" 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>';  
        
     }  
    
    ?>
    
    <?php print $tData ?>
    

    Then entire script works great, just need to tweak it do show a different table when there is no data and not sure how to define the condition based on the variables created from the XML that is embedded in the HTML $tdata table.

     

    Any advice or suggestions would be greatly appreciated.

     

    -Thanks

  17. Are those attributes indicating what type of data is contained by the element?

     

    Yes, exactly. It is just one element and those are all the attributes within that element. The output is based on the value of 1. I.E. if it's hail="1" then the output would be Hail but, if you parse the attribute the output would be 1. So I think I need a switch based on the value to get the text output. This is what I have come up with.

    $attrs = array();
                foreach($report->attributes() as $a => $b) {
        $attrs[$a] = $b;
    }
    
    $value = array_search('1', $attrs);
    
    switch ($value) {
        case 'tornado':
            echo "Tornado";
            break;
        case 'funnelcloud':
            echo "Funnel Cloud";
            break;
        case 'wallcloud':
            echo "Wall Cloud";
            break;
        case 'rotation':
            echo "Rotation";
            break; 
        case 'hail':
            echo "Hail";
            break; 
        case 'wind':
            echo "Wind";
            break;
        case 'flood':
            echo "Flood";
            break;  
        case 'flashflood':
            echo "Flash Flood";
                                 
    }   
    
    

    I really can't test it at the moment since the feed is empty at the moment. So am I on the right track or do you have any suggestions?

     

    -Thanks

  18. Never mind scratch this post above. That feed didn't have the data I needed. The feed that had the data I needed I was able to use my other method and was able to get it to work.

     

    BUT....

     

    This feed has something I haven't dealt with before and not sure how to parse it. The feed has element attributes which is not a big deal but some of the attributes of the element are like this....

    tornado="0" funnelcloud="0" wallcloud="0" rotation="0" hail="1" wind="0" flood="0" flashflood="0" other="0"
    

    So basically if there is a 1 it will output that data. So how do I parse that so it outputs the listed one? I am thinking I need an array maybe? If so any examples so I can get an idea?

     

    -Thanks

  19. Hello, I am apparently missing something and could use another set of eyes. I am parsing an XML file with simpleXML and I have done it several times with no issues and this one is pretty straight forward and should be easy but I am missing something. It displays the tables but the tables are empty. So to test I echo one of the variables and nothing shows. It's strange that the tables are outputting but with no data.

     

     

    Here is example of the XML I am parsing.

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
    <channel>
    <atom:link href="http://www.spotternetwork.org/feeds/rss-reports.xml" rel="self" type="application/rss+xml" />
    <title>Spotter Network Reports</title>
    <description>The last 3 hours of weather reports from the SN community</description>
    <link>http://www.spotternetwork.org</link>
    <item><title>Hail Size: 0.88" (Nickel) near 2 miles WSW of COLLYER, KS</title>
    <geo:lat>39.024000000000000</geo:lat>
    <geo:long>-100.148000000000000</geo:long>
    <description>"(Reported By) Daniel Shaw (Time) 2013-05-08 01:45:00 UTC (Notes) Falling now."</description>
    
    <link>http://www.spotternetwork.org/google.php</link>
    <guid>http://www.spotternetwork.org/report.php?id=13685</guid>
    </item>
    <item><title>Hail Size: 1.00" (Quarter) near 0 miles N of QUINTER, KS</title>
    <geo:lat>39.070000000000000</geo:lat>
    <geo:long>-100.235000000000000</geo:long>
    <description>"(Reported By) Daniel Shaw (Time) 2013-05-08 01:36:00 UTC (Notes) Fell 1min ago."</description>
    <link>http://www.spotternetwork.org/google.php</link>
    <guid>http://www.spotternetwork.org/report.php?id=13684</guid>
    
    </item>
    <item><title>Hail Size: 0.75" (Penny) near 8 miles SSW of GREENSBURG, KS</title>
    <geo:lat>37.498316666666700</geo:lat>
    <geo:long>-99.320266666666700</geo:long>
    <description>"(Reported By) John Guyton (Time) 2013-05-08 00:56:00 UTC (Notes) A few pennys mixed in with pea and dime size hail. Moderate amount has fallen in the last 5 minutes and continues to fall."</description>
    <link>http://www.spotternetwork.org/google.php</link>
    <guid>http://www.spotternetwork.org/report.php?id=13683</guid>
    </item>
    </channel>
    </rss>
      
    
    What am I missing?

    -Thanks

     

    Here is the example of the code I am using to parse it.

    $data = "http://www.spotternetwork.org/feeds/rss-reports.xml";
    $xml = simplexml_load_file($data);
    
    foreach($xml->channel->item as $item){
    
        $title = $item['title'];
        $desc = $item['description'];
        
    echo $desc;
            
    // construct data for table display
      $tData .= '<table style="width: 100%; margin: 0px auto; background-color:<?php print ($bkgColor); ?>;" cellpadding="0" cellspacing="0">
     <tbody><tr>
      <td style="'.$tbrdr.';'.$sbrdr.'; padding: 2px 0px 2px 6px;  background-image:url('.$imagesDir.'headerbgd2.gif); color: '.$dtColor.'"><b>'.$title.'</b>
     </td>
     </tr>
     <tr>
      <td class="opacity" style="'.$sbrdr.'; padding: 6px 0px 0px 6px; background-color: '.$bc.';">'.$desc.'</td>
     </tr>
     <tr>
      <td class="opacity" style="'.$sbrdr.'; line-height:5px; background-color:'.$bc.'"> </td>
     </tr>
     <tr>
      <td class="opacity" style="'.$sbrdr.'; '.$bbrdr.'; padding: 2px 6px 6px 6px; background-color:'.$bc.'">'.$desc.'</td></tr></tbody></table>
    <table style="margin-bottom: 5px;" 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>';
    
            
    }
    
    ?>
    
    
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.