让我们烤点甜饼(做饼图)
成功地安装了PHP地Shockwave Flash支持后,就可以用PHP创建Shockwave文件了。学习的最好方法就是直接跳到程序去,所以下面就让我们看看程序。第一个文件包括怎样使用类的示例代码,同时也显示了如何将一个Flash文件嵌入到HTML文档中。
// include class needed for flash graph
include("class.pie.flash.php");
mysql_connect ("localhost", "root", "");
$query = "SELECT DISTINCT city_name, COUNT(city_id)
FROM city
GROUP BY city_name;";
$result = mysql_db_query ("hermes",$query);
while ($row = mysql_fetch_array ($result)) {
$city_counts[] = $row["COUNT(city_id)"];
$city_names[] = $row["city_name"];
}
mysql_free_result ($result);
// Instantiate new object
$graph = new flash_pie($city_counts, "city.swf");
// set graph title (should not exceed about 25 characters)
$graph->pie_title("City Results", 30);
// set graph legend
$graph->pie_legend($city_names);
// show graph
$graph->show();
// free resources
$graph->close();
?>