Author Topic: Two advforecast2.php scripts in a single page?  (Read 393 times)

0 Members and 2 Guests are viewing this topic.

Offline Gerry0587

  • Senior Member
  • **
  • Posts: 74
Two advforecast2.php scripts in a single page?
« on: September 12, 2024, 07:25:06 PM »
Hello! I’m trying to add two .advforecast2.php scripts (with different file names) in a single page so that I can add the Miami and Orlando forecast, but no luck. It only allows me to add just one.

Any suggestions on how can I add these scritps for both cities in a single page so they can show as the one in the photo for Orlando and the other for Miami.

Thank you!

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9548
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Two advforecast2.php scripts in a single page?
« Reply #1 on: September 13, 2024, 01:40:28 PM »
Alas, no, you can't just include_once("advforecast2.php") on a single page.. the script is not designed to coexist with itself on one page.

You may be able to sidestep the issue by using include_once("advforecast2.php") for the first one, and a readfile("https://your.website.com/advforecast2.php?z=1&include=Y"); for the second script instance.. then the readfile() will get the page and echo it to your page where you place the page.

You'll likely have to twiddle with the argument on the URL to get the correct entry args on the URL to just get the icons you want.
See https://saratoga-weather.org/scripts-carterlake.php#advforecast for details.
Try loading the URL you use in a browser to see what it returns and adjust as needed.
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline Gerry0587

  • Senior Member
  • **
  • Posts: 74
Re: Two advforecast2.php scripts in a single page?
« Reply #2 on: September 13, 2024, 09:20:02 PM »
Hi.  Thank you! Im almost there... Tried:  <?php readfile("https://.... advforecast3.php?z=1&include=Y"); ?>..How can I eliminate the forecast text detail, so that only the forecast graphics shows as the image above... Thanks again!

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9548
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Two advforecast2.php scripts in a single page?
« Reply #3 on: September 13, 2024, 10:24:03 PM »
Ahh... the script wasn't built to just display icons and nothing else.  I suggest you create a 'stub' script to call advforecast2.php and just print the number of icons you want.

Quote
<?php
# Stub program to invoke NWS forecast and just print icons
#
$doPrintNWS = false; // don't print output.. just return values (and status in HTML comments)
$_GET['z'] = 1; // or the number in the $NWSforecasts array of the forecast you want
$maxIcons = 9; // set to number icons to print
include_once("advforecast2.php");
?>
<table>
      <tr valign ="top" align="center">
<?php
    for ($i = 0; $i < $maxIcons; $i++) {
      print "<td style=\"width: 11%;\"><span style=\"font-size: 8pt;\">$forecasticons[$i]</span></td>\n";
    }
?>
  </tr>
  <tr valign ="top" align="center">
  <?php
    for ($i = 0; $i < $maxIcons; $i++) {
      print "<td style=\"width: 11%;\">$forecasttemp[$i]</td>\n";
    }
?>
  </tr>
  </table>

Then you can do readfile("https://your.website.com/stubscript.php") to include the icons in your other page.
« Last Edit: September 13, 2024, 11:23:08 PM by saratogaWX »
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline Gerry0587

  • Senior Member
  • **
  • Posts: 74
Re: Two advforecast2.php scripts in a single page?
« Reply #4 on: September 14, 2024, 04:22:26 PM »
Hi there. I tried the following:

This code is for the stubscript.php file
Code: [Select]
<?php
# Stub program to invoke NWS forecast and just print icons
#
$doPrintNWS false// don&#39;t print output.. just return values (and status in HTML comments)
$_GET[&#39;z&#39;] = 1; // or the number in the $NWSforecasts array of the forecast you want
$maxIcons 9// set to number icons to print
include_once("advforecast4.php");
?>

<table>
      <tr valign ="top" align="center">
          <h4>Updated: <?php print $forecastupdated?></h4>
            &nbsp;</h3>

<h5><?php print $forecastwarnings?></h5>
<?php
    
for ($i 0$i $maxIcons$i++) {
      print 
"<td style=\"width: 11%;\"><span style=\"font-size: 8pt;\">$forecasticons[$i]</span></td>\n";
    }
?>

  </tr>
  <tr valign ="top" align="center">
  <?php
    
for ($i 0$i $maxIcons$i++) {
      print 
"<td style=\"width: 11%;\">$forecasttemp[$i]</td>\n";
    }
?>

  </tr>
  </table>

advforecast4.php file is for the Miami, Florida forecast.

No problem when I open the stubscript.php file and advforecast4.php files independently in the browser...Both shows the Miami Forecast.

However, when I paste this code:
Code: [Select]
<?php readfile("https://site.com/stubscript.php"); ? in the index.php file it shows the same content as the advforecast2111.php in the index page (Orlando, FL forecast).
« Last Edit: September 14, 2024, 04:47:11 PM by Gerry0587 »

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9548
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Two advforecast2.php scripts in a single page?
« Reply #5 on: September 14, 2024, 07:17:56 PM »
So first, you only need ONE advforecast2.php script to use.. no need to change names, just configure in the script
Quote
$NWSforecasts = array(
  // the entries below are for testing use.. replace them with your own entries if using the script
  // outside the AJAX/PHP templates.
  // ZONE|Location|point-forecast-URL  (separated by | characters
  "CAZ513|Saratoga, CA (WRH)|http://forecast.weather.gov/MapClick.php?CityName=Saratoga&state=CA&site=MTR&textField1=37.2639&textField2=-122.022&e=1&TextType=2",
...
);
The first entry is z=0, the second is z=1, etc.
So configure the first entry as Miami, the second as Orlando, etc.  Then using the stubscript.php with the $_GET['z'] = 1; should get Orlando to display.
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline Gerry0587

  • Senior Member
  • **
  • Posts: 74
Re: Two advforecast2.php scripts in a single page?
« Reply #6 on: September 14, 2024, 09:46:45 PM »
Bingo! Thank you so much for your help and support.  Im excited to share that I finally did it!

 

anything