<?php
require_once("C:\AppServ\www\Project\New Folder\jpgraph\jpgraph.php");
require_once("C:\AppServ\www\Project\New Folder\jpgraph\jpgraph_radar.php");
$dbhost="localhost";
$dbuser="root";
$dbpass="admin";
$database="test";
$con=mysql_connect("$dbhost","$dbuser","$dbpass") or die ("cannot connect to mysql");
$a=mysql_select_db("$database",$con) or die ("cannot connect to database");
$username = $_GET["username"];
$sql1= "select AVG(interest) As avgpoint1 from activity where user_name = '$username' and type='Sports'";
$que1 = mysql_query($sql1);
while($rs1 = mysql_fetch_array($que1))
{
$data1 = $rs1["avgpoint1"];
}
$sql2 ="select AVG(interest) As avgpoint2 from activity where user_name = '$username' and type='Social Services'";
$que2 = mysql_query($sql2);
while($rs2 = mysql_fetch_array($que2))
{
$data2 = $rs2["avgpoint2"];
}
$sql3 ="select AVG(interest) As avgpoint3 from activity where user_name = '$username' and type='Ethics and Personality'";
$que3 = mysql_query($sql3);
while($rs3 = mysql_fetch_array($que3))
{
$data3 = $rs3["avgpoint3"];
}
$sql4 ="select AVG(interest) As avgpoint4 from activity where user_name = '$username' and type='Academic and Professional Skills'";
$que4 = mysql_query($sql4);
while($rs4 = mysql_fetch_array($que4))
{
$data4 = $rs4["avgpoint4"];
}
$sql5 ="select AVG(interest) As avgpoint5 from activity where user_name = '$username' and type='Arts and Culture'";
$que5 = mysql_query($sql5);
while($rs5 = mysql_fetch_array($que5))
{
$data5 = $rs5["avgpoint5"];
}
$sql6 ="select AVG(interest) As avgpoint6 from activity where user_name = '$username' and type='Others'";
$que6 = mysql_query($sql6);
while($rs6 = mysql_fetch_array($que6))
{
$data6 = $rs6["avgpoint6"];
}
$mygraph = new RadarGraph (570,450);
$mygraph->SetShadow();
$mygraph->title->Set("Show user's interested point for each type of activity");
$titles=array("Ethics and Personality","Social Services","Arts and Culture","Academic and Professional Skills","Sports","Others");
$mygraph->SetTitles($titles);
$mygraph->grid->Show();
$mygraph->grid->SetLineStyle('dotted');
$mygraph->grid->SetColor('red');
$data=array($data3,$data2,$data5,$data4,$data1,$data6);
$radplot1=new RadarPlot($data);
$radplot1->SetColor('blue','khaki1');
$radplot1->SetLineWeight(2);
$mygraph->Add($radplot1);
$mygraph->Stroke();
?>
อีกไฟล์นึงนะครับ Code (PHP)
<?php
require_once("C:\AppServ\www\Project\New Folder\jpgraph\jpgraph.php");
require_once("C:\AppServ\www\Project\New Folder\jpgraph\jpgraph_radar.php");
$dbhost="localhost";
$dbuser="root";
$dbpass="admin";
$database="test";
$con=mysql_connect("$dbhost","$dbuser","$dbpass") or die ("cannot connect to mysql");
$a=mysql_select_db("$database",$con) or die ("cannot connect to database");
$username = $_GET["username"];
$sql1= "select * from activity where user_name = '$username' and type='Sports'";
$que1 = mysql_query($sql1);
$num1 = mysql_num_rows($que1);
$sql2 ="select * from activity where user_name = '$username' and type='Social Services'";
$que2 = mysql_query($sql2);
$num2 = mysql_num_rows($que2);
$sql3 ="select* from activity where user_name = '$username' and type='Ethics and Personality'";
$que3 = mysql_query($sql3);
$num3 = mysql_num_rows($que3);
$sql4 ="select *from activity where user_name = '$username' and type='Academic and Professional Skills'";
$que4 = mysql_query($sql4);
$num4 = mysql_num_rows($que4);
$sql5 ="select * from activity where user_name = '$username' and type='Arts and Culture'";
$que5 = mysql_query($sql5);
$num5 = mysql_num_rows($que5);
$sql6 ="select * from activity where user_name = '$username' and type='Others'";
$que6 = mysql_query($sql6);
$num6 = mysql_num_rows($que6);
$mygraph = new RadarGraph (570,450);
$mygraph->SetShadow();
$mygraph->title->Set("Show user activity divide by activity type");
$titles=array("Ethics and Personality","Social Services","Arts and Culture","Academic and Professional Skills","Sports","Others");
$mygraph->SetTitles($titles);
$mygraph->grid->Show();
$mygraph->grid->SetLineStyle('dotted');
$mygraph->grid->SetColor('red');
$data=array($num3,$num2,$num5,$num4,$num1,$num6);
$radplot1=new RadarPlot($data);
$radplot1->SetColor('blue','khaki1');
$radplot1->SetLineWeight(2);
$mygraph->Add($radplot1);
$mygraph->Stroke();
?>
ปัญหามีอยู่ตรงตัวแปร username ที่ผมรับเข้ามาครับ โดย ถ้าผมมี user สมมติชื่อ test แล้วใส่ค่า test ไปตรงๆ แทน $username มันจะสามารถแสดงกราฟที่สมบูรณ์ได้ครับ แต่ถ้าใส่ ว่า $ username ไฟล์ข้างบนจะแสดง error ส่วนไฟล์ข้างล่างจะแสดงข้อมูลได้ 0 ทุกแกนเลยครับ รบกวนแนะนำด้วยนะครับ พอดี ใกล้ส่ง project แล้วอ่าครับ ขอบคุณล่วงหน้าสำหรับคำตอบนะครับ ดึกๆจะเข้ามานะครับ