PDA

View Full Version : when $x ='01'; $x++: Returns '2' NOT '02'???


fuzzy1
12-03-2006, 01:18 AM
Hey All,
The Following will return '2006-2-Joe' when I need '2006-02-Joe'
//for context, $curName would be something like 2006-01-Joe through 2006-13-Joe
//where '01 & 13 are NOT DATES.
//$userString = substr($curName, -8);
//$periodString = substr($curName, 5, 2);
// so for arguement sake say that...
$Y = date('Y');
$periodString='01';
$userString='Joe';
$time_to_update_template = $today;
if ($time_to_update_template = $today){
$periodString+=1;
$newTemplate = "$Y.'-'.$periodString.'-'.$userString";
}
// which will return '2006-2-Joe' and not '2006-02-Joe'
Please,
How do I fix it so I get 01-09?
How do I set it so that it starts over after 13 (or on the new year)?
cause I can't seem make this... $period=1;
while($i<=13)
{
$period++;
} ...work for me in this context:eek:

fuzzy1
12-03-2006, 02:05 AM
if ($periodString <= 12){
$periodString+=1;
}else{$periodString=1;}
$newTemplate = sprintf('%04d-%02d-%s', $Y, $periodString, $userString);

Linark
12-03-2006, 01:15 PM
Will knock you something up - but had to go out!

See my next post below...

Linark
12-03-2006, 03:28 PM
Is this what you want:<?PHP

$newTemplate = "";

// There are 12 months so stop at 12...
$our_limit = 12;

$Y = date('Y');
$periodString = "01";
$userString = 'Joe';


for($i=0; $i < $our_limit; $i++ ) {

if (strlen($periodString) < 2 ) { $periodString = "0" . $periodString; }

$newTemplate .= $Y . "-" . $periodString . "-" . $userString . "<br />\n";

$periodString++;

}


echo $newTemplate;

?>

Just something I knocked up quickly.

fuzzy1
12-04-2006, 06:00 PM
Thanks Linark,
One of the shortcomings of this forum is the its lack of a thread tool to mark an inquiry RESOLVED. Which, I tried to accomplish in my last post, thanks for the effort nonetheless!
Kind Regards,
TJ