hi every one,
I m tring to make on webapplication with PHP and MSSQL2005.This simple website has some report and chart those r dynamically update from my MSSQL db.I m using fusion chart free for charting.
I have used this codes for report.
1.
<?php
2.
include('DBConn.php');
3.
include("FusionCharts_Gen.php");
4.
5.
$link = connectToDB();
6.
7.
$stmt=mssql_init("AreaWiseMonthlyRpt", $link);
8.
$date=$_REQUEST['gourl'];
9.
10.
mssql_bind($stmt, "@date", $date, SQLVARCHAR, FALSE);
11.
$result = mssql_execute($stmt);
12.
13.
echo '<table width="900" border="1" align="center" cellpadding="2" cellspacing="0"><tr bgcolor="#999999">';
14.
15.
echo '<th border="1">'.mssql_field_name($result, 0).'</th>';
16.
echo '<th border="1">'.mssql_field_name($result, 3).'</th>';
17.
echo '<th border="1">'.mssql_field_name($result, 4).'</th>';
18.
echo '<th border="1">'.mssql_field_name($result, 6).'</th>';
19.
echo '<th border="1">'.mssql_field_name($result, 7).'</th>';
20.
echo '<th border="1">'.mssql_field_name($result, 9).'</th>';
21.
echo '<th border="1">'.mssql_field_name($result, 10).'</th>';
22.
echo '<th border="1">'.mssql_field_name($result, 13).'</th>';
23.
echo '<th border="1">'.mssql_field_name($result, 15).'</th>';
24.
echo '<th border="1">'.mssql_field_name($result, 16).'</th>';
25.
// Define $color=1
26.
$color="1";
27.
/* Fetch values */
28.
while($rows=mssql_fetch_row($result)){
29.
if($color==1){
30.
echo '<tr bgcolor="#ECE9D8">';
31.
echo '<td border="0">'.$rows["0"].'</td>';
32.
echo '<td border="0">'.$rows["3"].'</td>';
33.
echo '<td border="0">'.$rows["4"].'</td>';
34.
echo '<td border="0">'.$rows["6"].'</td>';
35.
echo '<td border="0">'.$rows["7"].'</td>';
36.
echo '<td border="0">'.$rows["9"].'</td>';
37.
echo '<td border="0">'.$rows["10"].'</td>';
38.
echo '<td border="0">'.$rows["13"].'</td>';
39.
echo '<td border="0">'.$rows["15"].'</td>';
40.
echo '<td border="0">'.$rows["16"].'</td>';
41.
// Set $color==2, for switching to other color
42.
$color='2';
43.
}
44.
// When $color not equal 1, use this table row color
45.
else {
46.
echo '<tr bgcolor="#FFFFFF">';
47.
echo '<td border="0">'.$rows["0"].'</td>';
48.
echo '<td border="0">'.$rows["3"].'</td>';
49.
echo '<td border="0">'.$rows["4"].'</td>';
50.
echo '<td border="0">'.$rows["6"].'</td>';
51.
echo '<td border="0">'.$rows["7"].'</td>';
52.
echo '<td border="0">'.$rows["9"].'</td>';
53.
echo '<td border="0">'.$rows["10"].'</td>';
54.
echo '<td border="0">'.$rows["13"].'</td>';
55.
echo '<td border="0">'.$rows["15"].'</td>';
56.
echo '<td border="0">'.$rows["16"].'</td>';
57.
58.
$color='1';
59.
}
60.
}
61.
62.
echo '</tr></table>';
63.
?>
and code for charts:
1.
<?php
2.
# Create pie 3d chart object using FusionCharts PHP Class
3.
$FC = new FusionCharts("Column2D","650","450");
4.
5.
# Set Relative Path of swf file.
6.
$FC->setSwfPath("FusionCharts/");
7.
8.
//Store chart attributes in a variable for ease of use
9.
$strParam="caption=loan Outstanding;subCaption=BDT;pieSliceDepth=30; showBorder=1;showNames=1;formatNumberScale=0;numberSuffix= Units;decimalPrecision=0";
10.
11.
# Set chart attributes
12.
$FC->setChartParams($strParam);
13.
//Pass the SQL Query result to the FusionCharts PHP Class function
14.
//along with field/column names that are storing chart values and corresponding category names
15.
//to set chart data from database
16.
$strQuery=mssql_init("AreaWiseMonthlyRpt", $link);
17.
$date=$_REQUEST['gourl'];
18.
19.
mssql_bind($strQuery, "@date", $date, SQLVARCHAR, FALSE);
20.
21.
$result = mssql_execute($strQuery);
22.
23.
if ($result) {
24.
$FC->addDataFromDatabase($result, "TotalLoanOutstanding", "AreaName");
25.
}
26.
27.
28.
# Render the chart
29.
$FC->renderChart();
30.
?>
it is working well but problem is there are 2 reports and 5 charts in same page. All the chart and reports r using same store procedure "AreaWiseMonthlyRpt". 8 times execution of same procedure make the application very slow.My question is how can i execute the procedure once and reuse every time for every chart. I m new in php programming and I m still learning php.Plz kindly help me.