|
|
|
ผมอยากให้ jpgraph แสดงแบบเป็นกลุ่มและรวมค่าครับ ผมต้องทำไงครับ(ขอบคุณครับ) |
|
|
|
|
|
|
|
Code (PHP)
CREATE TABLE `test` (
`test_id` int(3) unsigned NOT NULL auto_increment,
`test_name` varchar(30) collate utf8_unicode_ci NOT NULL,
`test_num` int(5) unsigned NOT NULL,
PRIMARY KEY (`test_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=8 ;
--
-- dump ตาราง `test`
--
INSERT INTO `test` VALUES (1, 'AAA', 2);
INSERT INTO `test` VALUES (2, 'AAA', 8);
INSERT INTO `test` VALUES (4, 'BBB', 5);
INSERT INTO `test` VALUES (5, 'CCC', 8);
INSERT INTO `test` VALUES (6, 'AAA', 4);
INSERT INTO `test` VALUES (7, 'CCC', 6);
DB
Code (PHP)
<?php
@mysql_connect("localhost", "root", "1234") or die(mysql_error());
mysql_select_db("test_graph");
$sql = "SELECT* FROM test;";
$result = mysql_query($sql);
include("JpGraph/src/jpgraph.php");
include("JpGraph/src/jpgraph_pie.php");
$g = new PieGraph(500, 500);
$title = iconv("tis-620", "utf-8", "ทดสอบกราฟวงกลม");
$g->title->Set($title);
$g->title->SetFont(FF_JASMINE, FS_BOLD, 18);
$legends = array();
$data_graph = array();
while($data = mysql_fetch_array($result)) {
$lg = iconv("tis-620", "utf-8", $data['test_name']);
array_push($legends, $lg);
array_push($data_graph, $data['test_num']);
}
$pie = new PiePlot($data_graph);
$pie->SetLegends($legends);
$g->Add($pie);
$g->Stroke();
?>
Tag : PHP
|
|
|
|
|
|
Date :
2013-11-14 22:56:22 |
By :
TeeKub |
View :
781 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เปลี่ยนคำสั่ง SQL เป็น
Code (SQL)
SELECT test_name, SUM(test_num) AS test_num FROM test GROUP BY test_name
กรุ๊ปตามชื่อ
ลองดูครับ
|
|
|
|
|
Date :
2013-11-15 09:41:52 |
By :
WiTT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|