php file_get_contents yardım

3 Cevap php

i bir grafik içeren C:\\xampp\htdocs\exact\sample_pie.php bu dosya var. Burada kod:

<?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(); ?>

Bana yardım edin lütfen. teşekkürler.

3 Cevap

file_get_contents() gibi kullanarak sadece senaryoyu kendisi almak için gidiyor. Bu metin dosyası içerir ne olduğunu ve file_get_contents() yaptığı budur; kalay diyor tam olarak ne.

PHPGraphLib için veya başarısız kaynak kodu belgelerine bakarak deneyin. Eğer createGraph() yerine arayabilir, ya da belki sadece createGraph() için bir dosya adı parametresi iletebilirsiniz tasarruf yöntemi çeşit olmalıdır.

Bir dipnot düşmek, ben script olması gerekenden çok daha karmaşık olduğunu belirtmek gerekir. mysql_select_db() ve $graph->addData() Böyle bir şeye yeniden yazılabilir arasındaki her şey:

$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 önerilen kalanı için, grafik kütüphanesi belgelerine bakın.

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

Sen header() sample_pie.php içinde uygun içerik türünü ayarlamak için kullanmak isteyebilirsiniz.