繁体   English   中英

将 jpgraph 嵌入到其他 php 中

[英]embed jpgraph into with other php

我有一个依赖于上一页的 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(); ?>

这可能会晚,但以防万一或对于这里的其他人,您确实不需要将 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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM