问题已经解决了,可是我有个问题不明白. 假如在a.php的部分代码如下: <?php include('../include/dbclass.php'); include('../include/function.php'); . . . ?><?php classlist(); ?>在function.php中的部分代码如下: <?php function classlist(){ include('dbclass.php'); //这里如果include('dbclass.php')结果就会出现Fatal error: Cannot redeclare class db //如果注释掉include('dbclass.php');就正常了 $db=new db; . . . ?>我想问一下,为什么在function.php中没有include('dbclass.php'),却可以生成对象,对数据库进行操作呢?这是为什么呢?
不是很懂你的代码构造。Fatal error: Cannot redeclare class db in E:\www\BOA\include\dbclass.php on line 10 这句话说你重复定义了db这个类。有可能你在function.php里面include了dbclass.php但是在调用地方同时include了function.php 和 dbclass.php
假如在a.php的部分代码如下:
<?php
include('../include/dbclass.php');
include('../include/function.php');
.
.
.
?><?php classlist(); ?>在function.php中的部分代码如下:
<?php
function classlist(){
include('dbclass.php'); //这里如果include('dbclass.php')结果就会出现Fatal error: Cannot redeclare class db
//如果注释掉include('dbclass.php');就正常了
$db=new db;
.
.
.
?>我想问一下,为什么在function.php中没有include('dbclass.php'),却可以生成对象,对数据库进行操作呢?这是为什么呢?
就象 t500说的一样使用include_once或require_once
已经载入了,你在function.php里再加载dbclass.php
就两当于载入了两次
你把你包包含的文件直接换成文件的内容就可以看出问题了如果你在某个地方不能确定是否包含了dbclass.php你可以用require_once("dbclass.php")
这样只要前面包含了就不会再包包含,如果没有包含呢,就会把它包含进来了
我本来就是想在html里面嵌套php的,但现在把后缀名给改了,那文件的性质不就也跟着变了吗?
在html里面嵌套php,php代码无效,怎么解决?
test.html的代码如下,麻烦帮忙看一下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><?
$cj=array(0=>array("1","1"),1=>array("2","2"),2=>array("3","3"));
?><html>
<head>
<title> php嵌入到html或者javascript中 </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head> <body>
<center>查询结果</center>
<table border=1 align=center>
<tr><td>学号</td><td>成绩</td></tr>
<? for($i=0;$i<count($cj);$i++){?>
<tr><td><? echo $cj[$i][0];?></td><td><? echo $cj[$i][0];?></td></tr>
<? }?>
</table>
</body>
</html>