Author Topic: PHP Question on pulling this months data  (Read 763 times)

0 Members and 1 Guest are viewing this topic.

Offline CNYWeather

  • Forecaster
  • *****
  • Posts: 2297
    • CNYWeather
PHP Question on pulling this months data
« on: March 23, 2014, 12:38:36 PM »
I've been messing with this and trying to figure out how to do it.

In WD there are tags such as:
%avtempjan%
%avtempfeb%
%avtempmar%

and
%avtempjannow%
%avtempfebnow%
%avtempmarnow%

I'd like to get these onto my main page. My question is, can PHP replace the month like jan in the tag with the current month?
Someone lead me in the right direction if possible.

Tony
Tony




Offline Murry Conarroe

  • Contributor
  • ***
  • Posts: 143
    • Wildwood Weather
Re: PHP Question on pulling this months data
« Reply #1 on: March 23, 2014, 01:19:58 PM »
Try something like this.
Code: [Select]
$avtemp_current_month_now = ${'avtemp'.strtolower(date("M")).'now'};
$avtemp_current_month = ${'avtemp'.strtolower(date("M"))};
Murry

Offline CNYWeather

  • Forecaster
  • *****
  • Posts: 2297
    • CNYWeather
Re: PHP Question on pulling this months data
« Reply #2 on: March 23, 2014, 01:40:19 PM »
I created the functions Murry, but they're showing no data.
I think maybe it's could be because the WD tags have the month abbreviated?

The M would be the entire month name right?

I see this PHP function
Code: [Select]
string jdmonthname ( int $julianday , int $mode 0 )That will make the month a 3 letter abbreviation and strtolower makes it lower case?
« Last Edit: March 23, 2014, 01:45:55 PM by CNYWeather »
Tony




Offline Murry Conarroe

  • Contributor
  • ***
  • Posts: 143
    • Wildwood Weather
Re: PHP Question on pulling this months data
« Reply #3 on: March 23, 2014, 02:00:48 PM »
I created the functions Murry, but they're showing no data.
I think maybe it's could be because the WD tags have the month abbreviated?

The M would be the entire month name right?

I see this PHP function
Code: [Select]
string jdmonthname ( int $julianday , int $mode 0 )That will make the month a 3 letter abbreviation and strtolower makes it lower case?

The date("M") returns a 3 letter of the month and the strtolower makes it lower case.
The example I gave works for me and has the same values as the $avtempmar and $avtempmarnow variables.
Does the $avtempmar and $avtempmarnow variables have values before the code you added.
Murry

Offline CNYWeather

  • Forecaster
  • *****
  • Posts: 2297
    • CNYWeather
Re: PHP Question on pulling this months data
« Reply #4 on: March 23, 2014, 02:35:09 PM »
I must have been inserting the code incorrectly. I do have it working now Murry

Code: [Select]
<tr>
                    <td align="center" valign="top" style="text-align: center; border: 1px solid red;">
                          <?php langtrans('Mean Temp')?><br><? echo date('F Y'); ?><br/>
                          <strong><style="font-size: 14px"><?php echo $avtemp_current_month_now = ${'avtemp'.strtolower(date("M")).'now'} . $uomTemp;?></span></strong><br/>
                                              </td>
                    <td align="center" valign="top" style="text-align: center; border: 1px solid blue;">
                          <?php langtrans('Mean Temp<br>Since 2006'); ?><br/>
                          <strong><style="font-size: 14px"><?php echo $avtemp_current_month = ${'avtemp'.strtolower(date("M"))} . $uomTemp?></span></strong><br/>
                                              </td>
                </tr>

Looking good now. Thank you very much for the effort!!  :-)

Tony




Offline Murry Conarroe

  • Contributor
  • ***
  • Posts: 143
    • Wildwood Weather
Re: PHP Question on pulling this months data
« Reply #5 on: March 23, 2014, 02:43:56 PM »
If you are not using the new variables in any other locations you could simplify the code a bit by changing
Code: [Select]
<?php echo $avtemp_current_month_now = ${'avtemp'.strtolower(date("M")).'now'} . $uomTemp;?>
to
Code: [Select]
<?php echo ${'avtemp'.strtolower(date("M")).'now'} . $uomTemp;?>
And do likewise for the other variable.
Murry