我有一个依赖于上一页的php页面。根据我点击的客户类型,我将在下一页上看到他们的信息。我现在有一个问题,我必须将图形嵌入到php页面中,以便为该客户检索SQL数据。因为如果我在单独的PHP页面上有图表,它不知道我点击哪个客户来显示他们的统计数据。
如何将jpgraph嵌入其他php?
PHP
<?php
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($mysqli,"SELECT rid, pid, firstname, lastname, email FROM temp_members_db WHERE pid='$pid1' ");
echo "<table><tr><th>Namn</th><th>E-mail</th><th>Resultat</th><th>Ta bort kandidat</th></tr>";
while($row = mysqli_fetch_array($result))
{
$count= "SELECT COUNT(qid) AS 'Total' FROM result WHERE rid=".$row['rid']."";
$result01 = mysqli_query($mysqli, $count);
$resultArr01 = mysqli_fetch_array($result01);
$total= $resultArr01[0]*10;
$pointsummary= "SELECT SUM(points) AS 'Summary' FROM result WHERE rid=".$row['rid']."";
$result02 = mysqli_query($mysqli, $pointsummary);
$resultArr02 = mysqli_fetch_array($result02);
$sum= $resultArr02[0];
$result00 = ($total != 0 ? round($sum/$total*100) : 0);
$color = "#000000";
if (($result00 >= 1) && ($result00 <= 30))
$color = "#FF0000";
else if (($result00 > 30) && ($result00 <= 60))
$color = "#FF9900";
else if (($result00 > 60) && ($result00 <= 100))
$color = "#07d407";
echo "<tr><td><strong>
<form action='/devlopment/graph.php' method='GET'>
<input type='hidden' name='rid' value='".$row['rid']."'>
<input type='hidden' name='firstname' value='".$row['firstname']."'>
<input type='submit' class='resname' name='submit' value='".$row['firstname']." ".$row['lastname']."'>
</form>
</strong></td>
<td>".$row['email']."</td>
<td><strong><span style=\"color: $color\">".$result00."</span>%</strong></td>
<form action='deleterespondent2.php' method='post'>
<input type='hidden' name='rid' value='".$row['rid']."'>
<td> <input type='submit' class='mydel' value='Radera' onclick=\"return confirm('Vill du verkligen radera kandidaten? \\n\\nObservera att kandidatens eventuellt besvarade frågor och resultat raderas också!')\">
</form>
</td></tr>";
}
echo "</table>";
mysqli_close($mysqli);
?>
图表
<?php
require_once('jpgraph/jpgraph.php');
require_once('jpgraph/jpgraph_line.php');
require_once('jpgraph/jpgraph_bar.php');
session_start();
$val = (isset($_GET['rid'])) ?
"{$_GET['rid']}" : '';
$x_axis = array();
$y_axis = array();
$i = 0;
$con = mysqli_connect("root", "g", "f", "d");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con, "SELECT * FROM result WHERE rid=$val");
while ($row = mysqli_fetch_array($result)) {
$x_axis[$i] = $row["qid"];
$y_axis[$i] = $row["points"];
$i++;
}
mysqli_close($con);
$width = 600;
$height = 200;
$graph = new Graph($width, $height);
$graph->SetScale('textint');
$graph->title->Set('My Example');
$graph->xaxis->title->Set('(Fråga)');
$graph->xaxis->SetTickLabels($x_axis);
$graph->yaxis->title->Set('(Poäng)');
$barplot = new BarPlot($y_axis);
$graph->Add($barplot);
$graph->Stroke();
?>
答案 0 :(得分:0)
这可能要晚了,但是为了以防万一或对于这里的其他人,您真的不需要将JGraph放在同一页上。但是,嵌入将是正确的。基于以上所述,您可以执行以下操作:
//graphshow.php
<?php
require_once('jpgraph/jpgraph.php');
require_once('jpgraph/jpgraph_line.php');
require_once('jpgraph/jpgraph_bar.php');
if (isset($_GET['axes'])) {
$axes = explode("^^", $_GET['axes']);
$x_axis = $axes[0];
$y_axis = $axes[1];
}
$width = 600;
$height = 200;
$graph = new Graph($width, $height);
$graph->SetScale('textint');
$graph->title->Set('My Example');
$graph->xaxis->title->Set('(Fråga)');
$graph->xaxis->SetTickLabels($x_axis);
$graph->yaxis->title->Set('(Poäng)');
$barplot = new BarPlot($y_axis);
$graph->Add($barplot);
$graph->Stroke();
?>
然后在您的主php中,您需要在其中显示图形:
<?php
session_start();
$val = (isset($_GET['rid'])) ? "{$_GET['rid']}" : '';
$x_axis = array();
$y_axis = array();
$i = 0;
$con = mysqli_connect("root", "g", "f", "d");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con, "SELECT * FROM result WHERE rid=$val");
while ($row = mysqli_fetch_array($result)) {
$x_axis[$i] = $row["qid"];
$y_axis[$i] = $row["points"];
$i++;
}
$xy = $x_axis."^^".y_axis;
?>
<div>
<embed src="graphshow.php?axes=<?php echo $xy; ?>" height=80em; width=160em;> </embed>
</div>