Solved

PHP JPGraph and MSSQL

Posted on 2004-08-22
7
549 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

828 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