Can someone help me with the following code? The output works fine starting with the "categories" tag but the if loop only returns the last row from the db.
$strXML = "<chart>
";
$strQuery = "select inc_type, sum(num_of_occur) as cnt from inc_detail
group by inc_type";
$query2 = mysql_query($strQuery); //call string query
$strCategories = "<categories>
"; //create categories
while ($cat = mysql_fetch_array($query2))
{
$strCategories .= "<category label='" . $cat['inc_type'] . "' />
"; //display categories
};
$strCategories .= "</categories>
";
$strQuery2 = "select agency, inc_type, sum(num_of_occur) as cnt from inc_detail group by inc_type, agency order by agency";
$query3 = mysql_query($strQuery2); //call string query
$agency = null;
while ($ds = mysql_fetch_array($query3))
{
if( $ds['agency'] != $agency )
{
$K5 = "<dataset seriesName='" . $ds['agency'] . "' />
"; //create dataset
$agency = $ds['agency'];
}
$K5 .= "<set value='" . $ds['cnt'] . "' />
"; //display value of dataset
$K5 .= "</dataset>
";
}
$strXML .= $strCategories . $K5 . "</chart>"; //end of XML
echo $strXML;