Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Duplicate data showing from single variable

$
0
0

Hello, I am having a small issue which I think is just a simple problem but I can't seem to solve it. I have a small simple script that parses a text file of data sorts it through an array and creates variables to display the data in a table.

 

Problem I am having is when I call the script inside the page for it to be displayed with include statement it is showing duplicate data from a single variable. In this case $tnumber[1]. As you can see from this screen shot it shows "Tracking 1 active thunderstorms" twice.

 

GMap2.png

 

 

If I call the script directly in the browser it displays it correctly as shown below. So I am not sure as to why when I include the script in my page it shows duplicate data or if there is something I am doing wrong.

 

GMap1.png

 

 

Here is the code that parses the text file then creates the table to display the data. The variable that is being duplicated is on line 93 but I don't know why.

<?php

// The TRACreportshort takes Nexstorm's full TRACreport and shortens it to a more
// managable size for displaying.
//
// It chops up the vital storm cell info, places it in arrays, and redisplays it as we wish
//

// Set some default values

$measure = "mi"; // km, nm, or mi depending on your Nexstorm measurements

// Load the TRACreport and remove carriage returns, change the word 'no change' to 'steady'
$trac = implode('', file('lightning/nexstorm/TRACReport.txt'));
$tracnopara = preg_replace( '|\n|', '=', $trac );
$tracnopara = preg_replace( '|No change|', 'Steady', $tracnopara );

// Intialize values
$tracreport = "";
$tnumber = 1;
$alertflag = 0;
$tracwarning = "";

// If there aren't any thunderstorms, then say it

if (preg_match("/No thunderstorms detected/i", $trac)) {
		$tracreport = "<table width='100%' cellpadding='0' cellspacing='0' style='margin-top:15px; background-color:#000; color:#FFF;'>
			<tr>
			    <td style='padding: 3px 0px 3px 0px; font-size: .9em; text-align: center; color: #00FF00;'>No nearby thunderstorms detected</td>
			</tr>
               </table>"; }
	else {

// If there are thunderstorms, process them, putting them into various arrays

		// $tnumber[x] is for number of thunderstorms

		preg_match("/Tracking (.*) thunderstorms/Uis", $tracnopara, $tnumber);

		// $tid[x] is the ID number of the storm

		preg_match_all("/Thunderstorm ID (.*) detected/Uis", $tracnopara, $temp);
		$tid = $temp[1];

		// $tdtime[x] is the time detected

		preg_match_all("/detected (.*)=/Uis", $tracnopara, $temp);
		$tdtime = $temp[1];

		// $tdirection[x] is the direction of the storm

		preg_match_all("/Storm location bearing (.*) dgr/Uis", $tracnopara, $temp);
		$tdirection = $temp[1];

		// $tdistance[x] is the distance in $measure amounts

		preg_match_all("/distance (.*) $measure/Uis", $tracnopara, $temp);
		$tdistance = $temp[1];

		//$tintensity[x] is the intensity of the storm

		preg_match_all("/Intensity class (.*)=/Uis", $tracnopara, $temp);
		$tintensity = $temp[1];

		//$ttrend[x] is the trend of the storm

		preg_match_all("/Intensity trend (.*)=/Uis", $tracnopara, $temp);
		$ttrend = $temp[1];

                //$tactivity[x] Last recorded activity

		preg_match_all("/recorded activity (.*)=/Uis", $tracnopara, $temp);
		$tactivity = $temp[1];

		// Set working for the header based on number of thunderstorms

		if ($tnumber[1] == 1){
		} else {

			// Sometimes the TRACreport is empty so we need to say that

			$tracreport = "<table width='100%' cellpadding='0' cellspacing='0' style='margin-top:15px; background-color:#000; color:#FFF;'>
			<tr>
			    <td style='padding: 3px 0px 3px 0px; font-size: .9em; text-align: center; color: #00FF00;'>No data currently available or thunderstorms detected.</td>
			</tr>
               </table>";
		}

// This builds each line of text for each thunderstorm
// begin your table
$tracreport .=  "<table width='100%' cellpadding='0' cellspacing='0' style='margin-top:15px; background-color:#000; color:#FFF;'>
        <tr>
            <td style='padding: 3px 0px 3px 0px; font-size: .9em; text-align: center; color: #00FF00;'> Tracking " . $tnumber[1] . " active thunderstorms</td>
        </tr>
        <tr>
            <td>
            <table width='100%' cellpadding='0' cellspacing='0'>
                <tr>
                    <td>
                    <table id='tracReport' width='100%' cellpadding='0' cellspacing='0'>
                        <tr>
                            <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Cell ID</td>
                            <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Tracking Since</td>
                            <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Bearing</td>
                            <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Distance</td>
                            <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Intensity</td>
                            <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Trend</td>
                            <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Last Strike</td
                        </tr>"; // break the top part of the table
// create your loop
foreach($tid as $k => $v){
         $tracreport .= "<tr>
                            <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tid[$k] . "</td>
                            <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdtime[$k] . "</td>
                            <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdirection[$k] . "  °</td>
                            <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdistance[$k] . " miles</td>
                            <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . strtolower($tintensity[$k]) . "</td>
                            <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" .  trim(strtolower($ttrend[$k])) . "</td>
                            <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" .  trim(strtolower($tactivity[$k])) . "</td>
                        </tr>";
}  // close your loop
   // finish your table
    $tracreport .= "</table>
                    </table>
                    </td>
                </tr>
            </table>
            </td>
        </tr>
    </table>";

      }

echo $tracreport;



?>

-Thanks


Viewing all articles
Browse latest Browse all 13200

Trending Articles