让这是sample.php
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("final_year_sample",$con);
$qt=mysql_query("select * from gd_graph");
header("Content-Type:image/jpg");
$x_gap=40;
$x_max=$x_gap*13;
$y_max=250;
$im = ImageCreate($x_max, $y_max) or die ("Cannot Initialize new GD image stream");
$background_color = ImageColorAllocate($im, 234, 234, 234);
$text_color = ImageColorAllocate($im, 233, 14, 91);
$graph_color = ImageColorAllocate($im,25,25,250);
$x1=0;
$y1=0;
$first_one="yes";
while($nt = mysql_fetch_array($qt)){
$x2=$x1+$x_gap;
$y2=$y_max-$nt['sales'];
ImageString($im,2,$x2,$y2,$nt['month'],$graph_color);
if($first_one=="no"){
imageline($im,$x1, $y1,$x2,$y2,$text_color);
}
$x1=$x2;
$y1=$y2;
$first_one="no";
}
ImageJPEG($im);
?>
上面的sample.php代码效果很好,输出为 output generated from above code
我想做的是:
我想在下面的HTML页面中包含sample.php
<html>
<head>
<title>Front page</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="container">
<span id="title">Prototype for vehicle Routing problem Solution</span>
<div style="display:none;" id="graph_space">
<?php
include('sample.php');
?>
</div>
</div>
</body>
</html>
但是我收到以下错误,
答案 0 :(得分:0)
您不能将HTML文件包含在html文件中,因为html文件无法识别<?php ?>
标记
虽然你可以尝试这样做 在目录中创建.htaccess文件并将此代码添加到.htaccess文件
AddHandler x-httpd-php .html .htm
或
AddType application/x-httpd-php .html .htm
它将强制Apache服务器将PHP或HTM文件解析为PHP脚本
答案 1 :(得分:0)
您必须将文件声明为.php
页面,其中包含&#39; HTML&#39;。更改:page.html > page.php
然后您的include将运行,它无法在静态HTML页面上运行。想一想,哟。