我收到错误。 XML解析错误:文档元素之后的垃圾Locationhttp://localhost/fcdemo/get-data.php?year = 2012第2行,第1列
Undefined index: type in C:\EasyPHP-12.1\www\fcdemo\get-data.php on line 3.
Undefined index: month in C:\EasyPHP-12.1\www\fcdemo\get-data.php on line 5.
Undefined index: day in C:\EasyPHP-12.1\www\fcdemo\get-data.php on line 6.
我正在看第3,5和6行仍然无法弄明白。
这是我的代码。
<?php
//Sanitizing the input
$Type = $_GET['type'];
$Year = intval($_GET['year']);
$Month = intval($_GET['month']);
$Day = intval($_GET['day']);
//Months Names
$MonthsNames = array(null, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
//Prepare variables according to type-of-chart
switch($Type)
{
default:
case 'monthly':
$Query = "SELECT MONTH(Time) AS Value, COUNT(*) AS Total FROM `users` WHERE YEAR(Time)={$Year} GROUP BY Value";
$ResultArray = array_fill(1, 12, 0); // fill the Result array with 0 values for each month
$ChartHeading = 'Monthly New Users for the Year: '.$Year;
$XaxisName = 'Months';
break;
case 'daily':
$Query = "SELECT DAY(Time) AS Value, count(*) AS Total FROM `users` WHERE YEAR(Time)={$Year} AND MONTH(Time)={$Month} GROUP BY Value";
$ResultArray = array_fill(1, 31, 0); // fill the Result array with 0 values for each day
$ChartHeading = 'Daily New Users for the Month: '.$MonthsNames[$Month].'/'.$Year;
$XaxisName = 'Days';
break;
case 'hourly':
$Query = "select HOUR(Time) AS Value, count(*) AS Total FROM `users` WHERE YEAR(Time)={$Year} AND MONTH(Time)={$Month} AND DAY(Time)={$Day} GROUP BY Value";
$ResultArray = array_fill(0, 24, 0); // fill the Result array with 0 values for each hour
$ChartHeading = 'Hourly New Users for the Date: '.$Day.'/'.$MonthsNames[$Month].'/'.$Year;
$XaxisName = 'Hours';
break;
}
//Connect to database
require 'connect-to-database.php';
//Query the database
$QueryResult = mysql_query($Query);
//Fetch results in the Result Array
while($Row = mysql_fetch_assoc($QueryResult))
$ResultArray[$Row['Value']]=$Row['Total'];
//Generate Chart XML: Head Part
$Output = '<chart caption="'.$ChartHeading.'" xAxisName="'.$XaxisName.'" yAxisName="Users" showNames="1" bgColor="E6E6E6,F0F0F0" bgAlpha="100,50" bgRatio="50,100" bgAngle="270" showBorder="1" borderColor="AAAAAA" baseFontSize="12">';
//Generate Chart XML: Main Body
switch($Type)
{
default:
case 'monthly':
foreach($ResultArray as $MonthNumber => $value) // MonthNumber is month number (1-12)
$Output .= '<set value="'.$value.'" name="'.$MonthsNames[$MonthNumber].'" link="newchart-xmlurl-get-data.php?type=daily&year='.$Year.'&month='.$MonthNumber.'"/>';
break;
case 'daily':
foreach($ResultArray as $DayNumber => $value) // DayNumber is day (1-31)
$Output .= '<set value="'.$value.'" name="'.$DayNumber.'" link="newchart-xmlurl-get-data.php?type=hourly&year='.$Year.'&month='.$Month.'&day='.$key.'"/>';
break;
case 'hourly':
foreach($ResultArray as $HourNumber => $value) // HourNumber is hour (0-23)
$Output .= '<set value="'.$value.'" name="'.$HourNumber.'"/>';
break;
}
//Generate Chart XML: Last Part
$Output .= '</chart>';
//Set the output header to XML
header('Content-type: text/xml');
//Send output
echo $Output;
?>
答案 0 :(得分:0)
已解决谢谢
我将其更改为:更改为:
$Month = (isset($_GET['month']) && is_numeric($_GET['month']))?$_GET['month']:date("n");
$Year = (isset($_GET['year']) && is_numeric($_GET['year']))?$_GET['year']:date("Y");
$Day = (isset($_GET['day']) && is_numeric($_GET['day']))?$_GET['day']:date("d");
$Type = (isset($_GET['type']) ? $_GET['type'] : NULL);