I have a need to automatically switch out some field names on the 1st day of the month. Right now I'm having to upload new edited files every month. This has become a maintenance nightmare.
I need to switch out the ["???units"] for each line to accurately grab the right fields from my sql table.
There are only 12 fields: Janunits, Febunits, Marunits, Aprunits, Mayunits, Jununits, Julunits, Augunits, Sepunits, Octunits, Novunits, Decunits.
Any suggestions how I should go about doing this?
Thank you in advance for you assistance.
Tom
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Greetings!
I have a need to automatically switch out some field names on the 1st day of the month. Right now I'm having to upload new edited files every month. This has become a maintenance nightmare.
Below is the coding that defines the dates;
$lastmonth = date('m/y', mktime(0, 0, 0, date("m")-1 , date("d") , date("y")));
$lastyear = date('m/y', mktime(0, 0, 0, date("m") , date("d") , date("y")-1));
$lastyear_plus1_month = date('m/y', mktime(0, 0, 0, date("m")+1 , date("d") , date("y")-1));
Below is the Array for EZPDF to generate my printout data.
$table[] = array(
"$lastmonth"=>$row["Julunits"],
"$lastyear"=>$row["Augunits"],
"$lastyear_plus1_month"=>$row["Sepunits"]);
I need to switch out the ["???units"] for each line to accurately grab the right fields from my sql table.
There are only 12 fields: Janunits, Febunits, Marunits, Aprunits, Mayunits, Jununits, Julunits, Augunits, Sepunits, Octunits, Novunits, Decunits.
Any suggestions how I should go about doing this?
Thank you in advance for you assistance.
Tom
Try something like this:
$rowTitle = array(
1=>'Janunits',
2=>'Febunits',
3=>'Marunits',
4=>'Aprunits',
5=>'Mayunits',
6=>'Jununits',
7=>'Julunits',
8=>'Augunits',
9=>'Sepunits',
10=>'Octunits',
11=>'Novunits',
12=>'Decunits');
$curMo = date("n");
if($curMo==1){
$lastMo= 12;
$nextMo = $curMo+1;}
else{
$lastMo = $curMo-1;
$nextMo = ($curMo+1)%12;}
$table[] = array(
"$lastmonth"=>$row[$rowTitle[$lastMo]],
"$lastyear"=>$row[$rowTitle[$curMo]],
"$lastyear_plus1_month"=>$row[$rowTitle[$nextMo]]);
--
David
Change This:
$curMo = date("n");
...
$nextMo = ($curMo+1)%12;}
To This:
$curMo = date("n");
if($curMo==1){
$lastMo= 12;
$nextMo = $curMo+1;}
elseif($curMo==12){
$lastMo = $curMo-1;
$nextMo = 1;}
else{
$lastMo = $curMo-1;
$nextMo = $curMo+1;}
--
David
David,
You suggestion worked perfectly!
Thanks so much for your input.
Outstanding effort!
Very Best Regards,
Tom