|
PHP connection string |
Posted by Jorge Eduardo on Oct-26-2012 04:17 |
|
Hi Peter, I have an issue when trying to connect to a database. It's quite strange, but
if I include a php connection string, below the script call for phpchartdir.php, then the
chart doesn't renders. Instead the output is empty.
I also tested on a working sample script, instead of calling my conn string, included a
php command "echo 'anything'; " and again there is no chart. By removing the echo,
chart renders okay.
Thanks for your help.
<?php
require_once("../lib/phpchartdir.php");
echo 'anything';
# The data for the pie chart
$data = array(25, 18, 15, 12, 8, 30, 35);
# The labels for the pie chart
$labels = array("Labor", "Licenses", "Taxes", "Legal", "Insurance", "Facilities",
"Production");
# Create a PieChart object of size 360 x 300 pixels
$c = new PieChart(360, 300);
# Set the center of the pie at (180, 140) and the radius to 100 pixels
$c->setPieSize(180, 140, 100);
# Set the pie data and the pie labels
$c->setData($data, $labels);
# Output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));
?> |
Re: PHP connection string |
Posted by Jorge Eduardo on Oct-26-2012 04:41 |
|
Hi Peter this the script I want to run in order to create charts.
I've tested just the database part and works well, it shows me the expected result, but
when incorporated to the chart script, no chart at all. |
Re: PHP connection string |
Posted by Peter Kwan on Oct-26-2012 17:42 |
|
Hi Jorge,
Because the chart is an image, you cannot include HTML in it. For example, if you have a PNG/JPG/GIF image, you cannot open the image with Notepad, and add some text "anything" to it. If you do this, the image probably will become corrupted.
Also, you cannot include an image in HTML. You can only include an <IMG> tag. So if you want to show a web page with some text and a chart, the code should be:
<html><body>
<?php echo "anything" ?>
<img src="simplebar.php">
</body></html>
Note that the text should be in the HTML file, and the chart image should be in a separate PHP file (just like your other PNG/JPG/GIF must be in separate image files.)
You can certainly put database code in "simplebar.php", but please ensure the "database code" does not include other code that outputs HTML. Note that even an empty space or an empty line outside the <? ... ?> block is treated as HTML or text. So it is suggested your code should not include anything that is outside the <? ... ?> block, not even an empty space or line.
If the above still cannot solve the problem, is it possible to inform me your complete code (including the database code)? If you cannot post the code in this forum, you may email me at pkwan@advsofteng.net.
Hope this can help.
Regards
Peter Kwan |
|