Wrox Programmer Forums
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 17th, 2004, 04:45 AM
Authorized User
 
Join Date: Oct 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default header problem?

i have a php page called processreport.php that works fine. it will generate chart, bar graph, line graph or pie graph according to user selection from salesreport.php.However, later i add a button to it so that when the button is clicked, other chart and graph will displayed but i get the following error when i generate bar, line and pie graph and it works fine for the chart.
Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\project\processreport.php:11) in C:\Program Files\JpGraph\jpgraph-1.13\src\jpgraph.php on line 6666
Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\project\processreport.php:11) in C:\Program Files\JpGraph\jpgraph-1.13\src\jpgraph.php on line 6667
Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\project\processreport.php:11) in C:\Program Files\JpGraph\jpgraph-1.13\src\jpgraph.php on line 6668
Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\project\processreport.php:11) in C:\Program Files\JpGraph\jpgraph-1.13\src\jpgraph.php on line 6669
Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\project\processreport.php:11) in C:\Program Files\JpGraph\jpgraph-1.13\src\jpgraph.php on line 6671

this is the code that i added.
<html>
<head>
</head>
<body>
<form name="myform" method=POST action="drill.php">
<input type="submit" name="drillbut" value ="drill down">
</form>
</body>
</html>

could anyone tell me what's wrong with it and how to solve?

 
Old January 19th, 2004, 03:21 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, it looks like you're outputting HTML before another script tries to modify the header information. JPGraph sends headers to the client to let it know that it's outputting an image, not just text/html.

If you want an HTML form to appear, then you'll have to write it as a separate script than your graph generating script.

<?php // my_graph.php

// this is your PHP script that generates graphs

...
?>

<?php // my_form.php

// This is your php script that generates a form

echo "<form>...</form>\n";

// This is how you'd show a graph image on that page:

echo "<img src=\"my_graph.php\">\n";

?>


See, you submit the form variables to the HTML page, and it generates the IMG tags appropriate to create your graph.

The easiest way to forward the user selections is to append their choices to the URL of the image:

<img src="my_graph.php?user_input=some_value">


I hope this makes sense and that you can apply this to your application. The bottom line is that you **CAN NOT** output text from a script that generates binary output (for example, an image from jpGraph).


Take care,

Nik
http://www.bigaction.org/
 
Old February 14th, 2006, 08:59 PM
Registered User
 
Join Date: Feb 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jhourlad Send a message via Yahoo to jhourlad
Default

The problem with the solution above is that you can only display your chart above your page. But what if your site has a banner above each of your pages? (which is almost always the case) What if you need to load the graph in side a table?

One way to get around this problem is to put your graph in a separate page and load that file inside an <iframe> like the one below:

Code:
<iframe width="100%" height="210" src="stat.php" frameborder="0"></iframe>
where stat.php, the actual code to generate your graph, can be similar to the one below:

Code:
<?
include ("graph/jpgraph.php");
include ("graph/jpgraph_bar.php");
include 'config.inc.php';  // <-- You can load additional libraries like this one.

mysql_connect(DB_HOST,DB_USER,DB_PASS);
mysql_select_db(DB_NAME);

$sql = "SELECT * FROM isi_stat ORDER BY year DESC LIMIT 5";
$res = mysql_query($sql);

while ($row = mysql_fetch_assoc($res)) {
    $year[]   = $row['year'];
    $sem1[]   = $row['sem1'];
    $sem2[]   = $row['sem2'];
    $total[]  = $row['total'];
}

$graph = new Graph(280,180,'auto');    
$graph->SetScale("textlin");
$graph->SetShadow();
$graph->img->SetMargin(40,30,40,40);
$graph->xaxis->SetTickLabels($year);

#$graph->xaxis->title->Set('Year 2002');
#$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);

$graph->title->Set('ISI Enrollment Turnout');
$graph->title->SetFont(FF_FONT1,FS_BOLD);

$bplot1 = new BarPlot($sem1);
$bplot2 = new BarPlot($sem2);
$bplot3 = new BarPlot($total);

$bplot1->SetFillColor("orange");
$bplot2->SetFillColor("brown");
$bplot3->SetFillColor("darkgreen");

$bplot1->SetShadow();
$bplot2->SetShadow();
$bplot3->SetShadow();

$bplot1->SetShadow();
$bplot2->SetShadow();
$bplot3->SetShadow();

$gbarplot = new GroupBarPlot(array($bplot1,$bplot2,$bplot3));
$gbarplot->SetWidth(0.6);
$graph->Add($gbarplot);

$graph->Stroke();
?>
you can view the sample page here: http://clsu.edu.ph

Let me know what you think...



JHOURLAD ESTRELLA
Mobile and Web Applicatins Developer
 
Old June 23rd, 2006, 01:02 AM
Registered User
 
Join Date: Jun 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by hosefo81
 i have a php page called processreport.php that works fine. it will generate chart, bar graph, line graph or pie graph according to user selection from salesreport.php.However, later i add a button to it so that when the button is clicked, other chart and graph will displayed but i get the following error when i generate bar, line and pie graph and it works fine for the chart.
Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\project\processreport.php:11) in C:\Program Files\JpGraph\jpgraph-1.13\src\jpgraph.php on line 6666
Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\project\processreport.php:11) in C:\Program Files\JpGraph\jpgraph-1.13\src\jpgraph.php on line 6667
Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\project\processreport.php:11) in C:\Program Files\JpGraph\jpgraph-1.13\src\jpgraph.php on line 6668
Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\project\processreport.php:11) in C:\Program Files\JpGraph\jpgraph-1.13\src\jpgraph.php on line 6669
Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\project\processreport.php:11) in C:\Program Files\JpGraph\jpgraph-1.13\src\jpgraph.php on line 6671

this is the code that i added.
<html>
<head>
</head>
<body>
<form name="myform" method=POST action="drill.php">
<input type="submit" name="drillbut" value ="drill down">
</form>
</body>
</html>

could anyone tell me what's wrong with it and how to solve?

 
Old June 23rd, 2006, 01:06 AM
Registered User
 
Join Date: Jun 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I was also facing the same problem and after a long search in net got your solution.It really worked.Thanks a lot





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with matrix header (bug?) roy_mm Reporting Services 0 November 5th, 2006 02:54 AM
Header Function Problem. changusee2k PHP How-To 1 September 27th, 2006 02:45 AM
Header rediect problem .... ajutla Pro PHP 3 October 14th, 2004 09:13 AM
header redirection problem ronin2307 Pro PHP 2 September 1st, 2004 07:58 PM
Header redirection problem ronin2307 Beginning PHP 1 September 1st, 2004 04:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.