Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP JPGraph and MSSQL

Posted on 2004-08-22
7
Medium Priority
?
556 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
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…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

610 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