php file_get_contents 帮助

发布于 2024-08-07 11:00:31 字数 3162 浏览 3 评论 0原文

我有这个包含图表的文件 C:\\xampp\htdocs\exact\sample_pie.php 。这是代码:

<?php
include("phpgraphlib.php");
include("phpgraphlib_pie.php");
include("connection.php");
$graph=new PHPGraphLibPie(400,200); 
$link = mysql_connect('localhost', 'root', '');
mysql_select_db('exact');

$querypa = "SELECT COUNT(nature) FROM approved WHERE nature='Parade'";
$resultpa = mysql_query($querypa);
$printpa = mysql_result($resultpa,0);
$querycs = "SELECT COUNT(nature) FROM approved WHERE nature='Community Service'";
$resultcs = mysql_query($querycs);
$printcs = mysql_result($resultcs,0);
$queryga = "SELECT COUNT(nature) FROM approved WHERE nature='General Assembly'";
$resultga = mysql_query($queryga);
$printga = mysql_result($resultga,0);
$querypl = "SELECT COUNT(nature) FROM approved WHERE nature='Play/Showcase/Socio-Cultural Show/Film Showing'";
$resultpl = mysql_query($querypl);
$printpl = mysql_result($resultpl,0);
$queryco = "SELECT COUNT(nature) FROM approved WHERE nature='Competition/Sportsfest'";
$resultco = mysql_query($queryco);
$printco = mysql_result($resultco,0);
$queryfr = "SELECT COUNT(nature) FROM approved WHERE nature='Fund Raising'";
$resultfr = mysql_query($queryfr);
$printfr = mysql_result($resultfr,0);
$queryse = "SELECT COUNT(nature) FROM approved WHERE nature='Seminar/Convention/Conference/Training'";
$resultse = mysql_query($queryse);
$printse = mysql_result($resultse,0);


$totalAct=$printpa+$printga+$printpl+$printcs+$printco+$printfr+$printse;
$avepa=($printpa/$totalAct)*100;
$avecs=($printcs/$totalAct)*100;
$avega=($printga/$totalAct)*100;
$avepl=($printpl/$totalAct)*100;
$aveco=($printco/$totalAct)*100;
$avefr=($printfr/$totalAct)*100;
$avese=($printse/$totalAct)*100;
$pa=number_format($avepa,2);
$cs=number_format($avecs,2);
$ga=number_format($avega,2);
$pl=number_format($avepl,2);
$co=number_format($aveco,2);
$fr=number_format($avefr,2);
$se=number_format($avese,2);

$data=array("Parade"=>$pa, "General Assembly"=>$ga, "Play/Showcase/Socio-Cultural Show/Film Showing"=>$pl, "Community Service"=>$cs, "Competition/Sportsfest"=>$co, "Fund Raising"=>$fr, "Seminar/Convention/Conference/Training"=>$se);
$graph->addData($data);
$graph->setTitle("Total Activities per Nature of Activity");
$graph->setPrecision(2);
$graph->setLabelTextColor("0,0,0");
$graph->setLegendTextColor("0,0,0");
$graph->setGradient("210,245,255","pastel_purple");

$graph->createGraph();

?>

如何通过 php 脚本获取 .jpg 格式的图表?我尝试了这个 file_get_contents("C:\\xampp\htdocs\exact\sample_pie.php"); 但它只输出:

$pa, "General Assembly"=>$ga, "Play/Showcase/Socio-Cultural Show/Film Showing"=>$pl, "Community Service"=>$cs, "Competition/Sportsfest"=>$co, "Fund Raising"=>$fr, "Seminar/Convention/Conference/Training"=>$se); $graph->addData($data); $graph->setTitle("Total Activities per Nature of Activity"); $graph->setPrecision(2); $graph->setLabelTextColor("0,0,0"); $graph->setLegendTextColor("0,0,0"); $graph->setGradient("210,245,255","pastel_purple"); $graph->createGraph(); ?>

请帮助我。谢谢。

i have this file C:\\xampp\htdocs\exact\sample_pie.php that contains a graph. here's the code:

<?php
include("phpgraphlib.php");
include("phpgraphlib_pie.php");
include("connection.php");
$graph=new PHPGraphLibPie(400,200); 
$link = mysql_connect('localhost', 'root', '');
mysql_select_db('exact');

$querypa = "SELECT COUNT(nature) FROM approved WHERE nature='Parade'";
$resultpa = mysql_query($querypa);
$printpa = mysql_result($resultpa,0);
$querycs = "SELECT COUNT(nature) FROM approved WHERE nature='Community Service'";
$resultcs = mysql_query($querycs);
$printcs = mysql_result($resultcs,0);
$queryga = "SELECT COUNT(nature) FROM approved WHERE nature='General Assembly'";
$resultga = mysql_query($queryga);
$printga = mysql_result($resultga,0);
$querypl = "SELECT COUNT(nature) FROM approved WHERE nature='Play/Showcase/Socio-Cultural Show/Film Showing'";
$resultpl = mysql_query($querypl);
$printpl = mysql_result($resultpl,0);
$queryco = "SELECT COUNT(nature) FROM approved WHERE nature='Competition/Sportsfest'";
$resultco = mysql_query($queryco);
$printco = mysql_result($resultco,0);
$queryfr = "SELECT COUNT(nature) FROM approved WHERE nature='Fund Raising'";
$resultfr = mysql_query($queryfr);
$printfr = mysql_result($resultfr,0);
$queryse = "SELECT COUNT(nature) FROM approved WHERE nature='Seminar/Convention/Conference/Training'";
$resultse = mysql_query($queryse);
$printse = mysql_result($resultse,0);


$totalAct=$printpa+$printga+$printpl+$printcs+$printco+$printfr+$printse;
$avepa=($printpa/$totalAct)*100;
$avecs=($printcs/$totalAct)*100;
$avega=($printga/$totalAct)*100;
$avepl=($printpl/$totalAct)*100;
$aveco=($printco/$totalAct)*100;
$avefr=($printfr/$totalAct)*100;
$avese=($printse/$totalAct)*100;
$pa=number_format($avepa,2);
$cs=number_format($avecs,2);
$ga=number_format($avega,2);
$pl=number_format($avepl,2);
$co=number_format($aveco,2);
$fr=number_format($avefr,2);
$se=number_format($avese,2);

$data=array("Parade"=>$pa, "General Assembly"=>$ga, "Play/Showcase/Socio-Cultural Show/Film Showing"=>$pl, "Community Service"=>$cs, "Competition/Sportsfest"=>$co, "Fund Raising"=>$fr, "Seminar/Convention/Conference/Training"=>$se);
$graph->addData($data);
$graph->setTitle("Total Activities per Nature of Activity");
$graph->setPrecision(2);
$graph->setLabelTextColor("0,0,0");
$graph->setLegendTextColor("0,0,0");
$graph->setGradient("210,245,255","pastel_purple");

$graph->createGraph();

?>

how can i get the graph as a .jpg through php script? i tried this file_get_contents("C:\\xampp\htdocs\exact\sample_pie.php");
but it only outputs this:

$pa, "General Assembly"=>$ga, "Play/Showcase/Socio-Cultural Show/Film Showing"=>$pl, "Community Service"=>$cs, "Competition/Sportsfest"=>$co, "Fund Raising"=>$fr, "Seminar/Convention/Conference/Training"=>$se); $graph->addData($data); $graph->setTitle("Total Activities per Nature of Activity"); $graph->setPrecision(2); $graph->setLabelTextColor("0,0,0"); $graph->setLegendTextColor("0,0,0"); $graph->setGradient("210,245,255","pastel_purple"); $graph->createGraph(); ?>

please help me. thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一个人的旅程 2024-08-14 11:00:31

像这样使用 file_get_contents() 只会检索脚本本身。该文本是文件包含的内容,这就是 file_get_contents() 的作用;正如罐头上所说的那样。

如果失败,请尝试查看 PHPGraphLib 的文档或源代码。您应该可以调用某种保存方法来代替 createGraph(),或者您可以将文件名参数传递给 createGraph()

Using file_get_contents() like that is only going to retrieve the script itself. That text is what the file contains and that's what file_get_contents() does; exactly what it says on the tin.

Try looking at the documentation for PHPGraphLib or in the source code failing that. There should be some sort of save method you can call instead of createGraph() or maybe you can just pass a filename parameter to createGraph().

若有似无的小暗淡 2024-08-14 11:00:31

顺便说一句,我应该提到您的脚本比应有的要复杂得多。 mysql_select_db()$graph->addData() 之间的所有内容都可以重写为如下所示:

$data = array(
    'Parade' => 0,
    'Community Service' => 0,
    'General Assembly' => 0,
    'Play/Showcase/Socio-Cultural Show/Film Showing' => 0,
    'Competition/Sportsfest' => 0,
    'Fund Raising' => 0,
    'Seminar/Convention/Conference/Training' => 0
);

$sql = "SELECT nature, COUNT(*) AS cnt
          FROM approved
         WHERE nature IN ('" . implode("','", array_keys($data)) . "')
      GROUP BY nature";
$result = mysql_query($sql);

while ($row = mysql_fetch_assoc($result))
{
    $data[$row['nature']] = $row['cnt'];
}
$totalAct = array_sum($data);

foreach ($data as $nature => &$value)
{
    $value = number_format(100 * $value / $totalAct, 2);
}

对于其余部分,请参阅 Ollie Saunders 的图形库文档建议。

On a sidenote, I should mention that your script is a lot more complicated than it should be. Everything between mysql_select_db() and $graph->addData() could be rewritten into something like this:

$data = array(
    'Parade' => 0,
    'Community Service' => 0,
    'General Assembly' => 0,
    'Play/Showcase/Socio-Cultural Show/Film Showing' => 0,
    'Competition/Sportsfest' => 0,
    'Fund Raising' => 0,
    'Seminar/Convention/Conference/Training' => 0
);

$sql = "SELECT nature, COUNT(*) AS cnt
          FROM approved
         WHERE nature IN ('" . implode("','", array_keys($data)) . "')
      GROUP BY nature";
$result = mysql_query($sql);

while ($row = mysql_fetch_assoc($result))
{
    $data[$row['nature']] = $row['cnt'];
}
$totalAct = array_sum($data);

foreach ($data as $nature => &$value)
{
    $value = number_format(100 * $value / $totalAct, 2);
}

For the rest, consult the documentation of your graph library as Ollie Saunders suggested.

放手` 2024-08-14 11:00:31
<img src="/exact/sample_pie.php" />

您可能需要使用 header() 在sample_pie.php 中设置适当的内容类型。

<img src="/exact/sample_pie.php" />

You may want to use header() to set the appropriate Content-type from within sample_pie.php.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文