XML ..Chart Dates screwed up

NamecheapNamecheap
Watch
Impact
9
Chart has been working perfect until today.

The chart is suppose to display the the current as well last 11 months.. instead today the chart started displaying Nov 07 then Jan 09 Feb 09, March09 etc...

anyone see anything wrong with the code ?


$x = $xml->addChild('abscissa_data');

$year = date('Y');
$month = date('n');
$m = $month + 1;
$y = $year;
if ($m > 12)
$m = 1;
else
$y--;
$next_year = $y;

if (!$priceSpread) {
$e85 = $xml->addChild('ordinate_data');
$e85->addAttribute('seriesName', 'E85 Prices');
$e85->addAttribute('color', $e85_color);
$e85->addAttribute('size', '4');

$gas = $xml->addChild('ordinate_data');
$gas->addAttribute('seriesName', 'Gasoline Prices');
$gas->addAttribute('color', $gas_color);
$gas->addAttribute('size', '4');
}
else {
$price = $xml->addChild('ordinate_data');
$price->addAttribute('seriesName', 'Price Spread');
$price->addAttribute('color', $priceSpread_color);
$price->addAttribute('size', '4');
}

$time = array();
$time[$m] = mktime(0, 0, 0, $m, 1, $y);

for ($i = 0; $i < 12; $i++) {
$next_month = $m + 1;
if ($next_month > 12) {
$next_month = 1;
$next_year = $year + 1;
}
$time[$next_month] = mktime(0, 0, 0, $next_month, 1, $next_year);

$x_val = $x->addChild('x');
$x_val->addAttribute('value', date('M y',$time[$m]));

$Query = "Select ".$What." from `prices` where ".$Where."`timestamp` between '".$time[$m]."' and '".$time[$next_month]."'";
$Result = $Db->FetchArray($Query);


if ($priceSpread) {
$y_val = $price->addChild('y');
$y_val->addAttribute('value', $Result['priceSpread']?number_format($Result['priceSpread'], 2):'');
}
else {
$y_val = $e85->addChild('y');
$y_val->addAttribute('value', $Result['e85']?number_format($Result['e85'],2):'');

$y_val = $gas->addChild('y');
$y_val->addAttribute('value', $Result['gas']?number_format($Result['gas'],2):'');
}

$m = $next_month;
$year = $next_year;
}

echo $xml->asXML();
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable Domains — AI StorefrontUnstoppable Domains — AI Storefront
I know, my changes are not quite perfect, but this code should work.
(And don't forget to make a backup of your current code, just in case)

PHP:
<?
$x = $xml->addChild('abscissa_data');

$year = date('Y');
$month = date('n');

$m = $month + 1;
$y = $year;
if ($m > 12)
	$m = 1;
else
	$y--;

if (!$priceSpread) {
	$e85 = $xml->addChild('ordinate_data');
	$e85->addAttribute('seriesName', 'E85 Prices');
	$e85->addAttribute('color', $e85_color);
	$e85->addAttribute('size', '4');

	$gas = $xml->addChild('ordinate_data');
	$gas->addAttribute('seriesName', 'Gasoline Prices');
	$gas->addAttribute('color', $gas_color);
	$gas->addAttribute('size', '4');
} else {
	$price = $xml->addChild('ordinate_data');
	$price->addAttribute('seriesName', 'Price Spread');
	$price->addAttribute('color', $priceSpread_color);
	$price->addAttribute('size', '4'); 
}

$cur_month_time = mktime(0, 0, 0, $m, 1, $y);

for ($i = 0; $i < 12; $i++) {
	$next_month = $m + 1;
	if ($next_month > 12) {
		$next_month = 1;
		$next_year = $y + 1;
	}

	$next_month_time = mktime(0, 0, 0, $next_month, 1, $next_year);

	$x_val = $x->addChild('x');
	$x_val->addAttribute('value', date('M y',$cur_month_time));

	$Query = "Select ".$What." from `prices` where ".$Where."`timestamp` between '".$cur_month_time."' and '".$next_month_time."'";
	$Result = $Db->FetchArray($Query);

	if ($priceSpread) {
		$y_val = $price->addChild('y');
		$y_val->addAttribute('value', $Result['priceSpread']?number_format($Result['priceSpread'], 2):'');
	} else {
		$y_val = $e85->addChild('y');
		$y_val->addAttribute('value', $Result['e85']?number_format($Result['e85'],2):'');

		$y_val = $gas->addChild('y');
		$y_val->addAttribute('value', $Result['gas']?number_format($Result['gas'],2):'');
	}

	$m = $next_month;
	$y = $next_year;
	$cur_month_time = $next_month_time;
}

echo $xml->asXML();

?>
 
0
•••
Alex thank you very much..unfortunently I'm an Idiot and picked the wrong file..

Once I located the correct file I was able to fix (probably a band-aid approach.well see) it replacing if ($m > 12) with if ($m > 11) that gives me Jan-November 08..well see how it does when we change to December and the New year.. I'll probably be back ;)

I really appreciate your help ..it lead me on the right track and also helped me understand the coding better..
 
0
•••
CatchedCatched

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back