PHP variable doesn't echo in table when function called -


i have simple vars.php page:

<?php //vars.php $weekofdateselected = date('l, m/d/y', strtotime($monthyear)); $nextsundayofdateselected = date('l, m/d/y', strtotime('this sunday', strtotime($weekofdateselected)));  ?> 

i have php includes vars.php , builds table:

<html> <?php //analyticstest.php  include($_server['document_root']."/~/~/~/~/~/vars.php");  function weektable() {  echo "<table id=\"a\"> <tr> <th style=\"text-align: center;\"><a href=\"#\">< previous week</a></th> <th colspan=\"4\" style=\"text-align: center;\"><h2>week of "; echo $weekofdateselected; echo " - ";  echo $nextsundayofdateselected;  echo "</th> <th style=\"text-align: center;\"><a href=\"#\">next week ></a></th> </tr> </table>";  }  ?>  </html> 

basically, when call weektable() outputs correctly except php variables $weekofdateselected , $nextsundayofdateselected, output blank.

you need pass variables parameters function. otherwise out of scope.

function weektable($weekofdateselected,$nextsundayofdateselected) {     // ... } 

make sure pass them when call function:

 weektable($weekofdateselected,$nextsundayofdateselected); 

you can use global keyword bad programming practice not show here.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -