Solved

PHP JPGraph and MSSQL

Posted on 2004-08-22
7
548 Views
Last Modified: 2013-12-12
Hi,
I am having a problem using jpgraph with some php code.
FIrstly, the php script gets some data from mssql, then displays relevant data on a page
WHere the problem is, is i am calling an external .php to build the jpgraph graphs and i keep getting  image placeholders.  Im guessing this is because the headers for the page have already been sent.  Heres some code:

main.php
<?
  $bat_cur = 0;
  $lamp_cur = 0;
  $array_vol = 0;
  $mains_vol = 0;
  $bat_vol = 0;
$image = "fig1.php?name=B.Curr&val=$bat_cur&min=0&max=10";
require ('globals.inc');
$result = mssql_query("SELECT     TOP 1 SAT24R3.[Main Lamp Fail], SAT24R3.[Standy Lamp Fail], SAT24R3.[Inverter Fail], SAT24R3.[Mains Power Fail], SAT24R3.[Generator Fail],
                      SAT24R3.[Photo Cell Fail], SAT24R3.[Fuel Level Low], SAT24R3.[Security Door Open],
                      SAT24R3.[Rotation RPM], SAT24R3.[Battery Volts], SAT24R3.[Mains Volts], SAT24R3.[Array Volts], SAT24R3.[Lamp Current], SAT24R3.[Battery Current],
                      SAT24R3.MessageIdentifier
FROM         ST_Terminal_CommonName_Table INNER JOIN
                      DapDeliverMessage ON ST_Terminal_CommonName_Table.TerminalID = DapDeliverMessage.TerminalSubscriptionID INNER JOIN
                      SAT24R3 ON DapDeliverMessage.ID = SAT24R3.DapDeliverMessageID
ORDER BY DapDeliverMessage.ReceivedTimestamp DESC");
while ($data = mssql_fetch_array($result)) {
  $main_lamp = $data['0'];
  $standby_lamp = $data['1'];
  $inverter = $data['2'];
  $main_power = $data['3'];
  $generator = $data['4'];
  $photo_cell = $data['5'];
  $fuel_low = $data['6'];
  $door = $data['7'];
  $bat_cur = $data['13'];
  $lamp_cur = $data['12'];
  $array_vol = $data['11'];
  $mains_vol = $data['10'];
  $bat_vol = $data['9'];
  $rotation = $data['8'];
}

print ("
<body>

<table border =\"1\" font face=\"tahoma\" size=\"2\" width = \"50%\">
<tr>
<td><img src=\"fig1.php?name=B.Curr&val=$bat_cur&min=0&max=10&min=0&max=10\" border=0 align=center></td>
<td><img src=\"fig1.php?name=L.Curr&val=$lamp_cur&min=0&max=10\" border=0 align=center></td>
<td><img src=\"fig1.php?name=Array&val=$array_vol&min=0&max=10\" border=0 align=center></td>
<td><img src=\"fig1.php?name=Mains&val=$mains_vol&min=0&max=10\" border=0 align=center></td>
<td><img src=\"fig1.php?name=B.Volt&val=$bat_vol&min=0&max=10\" border=0 align=center></td>
<td><img src=\"fig1.php?name=Rot.RPM&val=$rotation&min=0&max=10\" border=0 align=center></td>



</tr>
<tr>
<td align=\"center\"><font face=\"tahoma\" size=2\">$bat_cur</td>
<td align=\"center\"><font face=\"tahoma\" size=2\">$lamp_cur</td>
<td align=\"center\"><font face=\"tahoma\" size=2\">$array_vol</td>
<td align=\"center\"><font face=\"tahoma\" size=2\">$mains_vol</td>
<td align=\"center\"><font face=\"tahoma\" size=2\">$bat_vol</td>
<td align=\"center\"><font face=\"tahoma\" size=2\">$rotation</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table border =\"1\" font face=\"tahoma\" size=\"2\" width = \"50%\">
<tr>
<td>Main Lamp</td><td><img src=\"$main_lamp.gif\"><br></td>
<td>Standby Lamp</td><td><img src=\"$standby_lamp.gif\"></td>
<td>Inverter</td><td><img src=\"$inverter.gif\"></td>
<td>Main Power</td><td><img src=\"$main_power.gif\"></td>
<td>Generator</td><td><img src=\"$generator.gif\"></td>
<td>Photo Cell</td><td><img src=\"$photo_cell.gif\"></td>
<td>Fuel Low</td><td><img src=\"$fuel_low.gif\"></td>
<td>Security Door</td><td><img src=\"$door.gif\"></td>

</tr>

</body>
</html>");
?>

fig1.php
<?PHP
$name = $_GET['name'];
$datay[] = $_GET['val'];
$minval = $_GET['min'];
$maxval = $_GET['max'];
include ("globals.inc");
include ("JPGraph/jpgraph.php");
include ("JPGraph/jpgraph_bar.php");

// Create the graph. These two calls are always required
$graph = new Graph(35, 150,"auto");    
$graph->SetScale("textlin",$minval,$maxval);

// Setup margin and titles
$graph->img->SetMargin(20,5,10,0);
$graph->yaxis->SetFont(FF_FONT0,FS_NORMAL,0.5);
$graph->title->Set($name);
$graph->title->SetFont(FF_FONT0,FS_NORMAL,0.5);
$graph->xaxis->SetFont(FF_FONT0,FS_NORMAL,0.5);
$graph->xaxis->scale->ticks->Set(1);
$graph->yaxis->SetLabelMargin(2);

// Create the bar plot
$bplot = new BarPlot($datay);

// Setup color for gradient fill style
$bplot->SetFillGradient("navy","lightsteelblue",GRAD_MIDVER);

// Set color for the frame of each bar
$bplot->SetColor("navy");
$bplot->SetWidth(1.0);
$graph->Add($bplot);

// Add the plot to the graph

$graph->Add($bplot);

// Display the graph
$graph->Stroke();
?>

Basically it displays an indicator graph for each of the values from the database.
Can someone help me out on this?
CHeers
D.
0
Comment
Question by:maunded
  • 3
  • 2
7 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 11867586
Does the image display correctly when you open it in a new window (right-click on the image -> copy link location, open that url in a new window) and see if there are any PHP-errors or something else which prevents the display of the image) Or is the image displayed correctly in that window?
0
 
LVL 1

Author Comment

by:maunded
ID: 11867589
If I right click and do Show Image it is OK
0
 
LVL 1

Author Comment

by:maunded
ID: 11869138
Its OK, I furgured that I need to use a function to create each of the graphs before I pass any data to the browser.
Not sure how I close an open question now tho???
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 48

Expert Comment

by:hernst42
ID: 11869402
0
 
LVL 1

Author Comment

by:maunded
ID: 11876639
I solved this problem by instead of calling an external file (fig1.php) to build the graphs, i created a function in the main php code and put the fig1.php code into that, so before I output anything to the browser, I call the function which creates the graph images.
Hope this can help someone a little more patient than I :)
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 11920589
Closed, 500 points refunded.
CetusMOD
Community Support Moderator
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question