0
有人可以幫我用下面的代碼嗎?輸出工作正常,從「categories」標記開始,但if循環只返回數據庫中的最後一行。而如果循環執行不正確
$strXML = "<chart> \n";
$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>\n"; //create categories
while ($cat = mysql_fetch_array($query2))
{
$strCategories .= "<category label='" . $cat['inc_type'] . "' /> \n"; //display categories
};
$strCategories .= "</categories> \n";
$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'] . "' /> \n"; //create dataset
$agency = $ds['agency'];
}
$K5 .= "<set value='" . $ds['cnt'] . "' /> \n"; //display value of dataset
$K5 .= "</dataset> \n";
}
$strXML .= $strCategories . $K5 . "</chart>"; //end of XML
echo $strXML;
感謝您的回覆,但我不明白你的解決方案。我瞭解while循環,但我是編程新手。如果你有一個非常有用的例子。 – user1033720