我有三个页面:group_data.php
,getters.php
和homepage.php
这些都包含在两个不同的目录中;
home
位于根文件夹中,而group_data.php
和getters.php
都位于inc/modules/
子文件夹中;
inc/modules/group_data.php
,inc/modules/getters.php
这是我的group_data.php页面中的代码:
function getComments($post_id){
$sql_query = mysql_query("SELECT * FROM replies WHERE pid = '$post_id'");
$row_count = mysql_num_rows($sql_query);
while($rows = mysql_fetch_assoc($sql_query)) {
$record_set[] = array('comment_count' => $row_count,
'pid' => $rows['pid'],
'date' => timeAgo($rows['date']),
'comment' => $rows['comment']
);
}
return $record_set;
}
function getFollowedGroupPosts($user_id){
$sql_query = mysql_query("SELECT gid FROM members WHERE uid = '$user_id'");
$row_count = mysql_num_rows($sql_query);
while( $rows = mysql_fetch_assoc($sql_query)) {
$tag = $rows['gid'];
$pushed_array = array_fill(0, $row_count, $tag );
$ids = join("','",$pushed_array);
$sql_bound = mysql_query("SELECT * FROM posts WHERE gid IN ('$ids')");
$row_count_b = mysql_num_rows($sql_bound);
while( $rows_b = mysql_fetch_assoc($sql_bound)) {
//get images url as comma seperated strings
$url_string = json_encode(getPostImages($rows_b['pid']));
$record_set[] = array('gid' => $rows_b['gid'],
'pid' => $rows_b['pid'],
'post' => $rows_b['post'],
'images' => getPostImages($rows_b['pid']),
'jImages' => $url_string,
'videos' => getPostVideos($rows_b['pid']),
'audios' => getPostAudios($rows_b['pid']),
'date' => timeAgo($rows_b['date']),
'username' => userIdToName($rows_b['uid']),
'filemap_id' => $rows_b['filemap_id'],
'group_name' => groupIdToName($rows_b['gid']),
'comments' => getComments($rows_b['pid']),
'likes' => checkLikeCount($rows_b['pid']),
'post_count' => $row_count_b);
}
}
return $record_set;
}
调用getfollowedGroupPosts()
函数可以在getters.php页面上运行,但是在homepage.php中包含getters.php页面会产生以下错误;
致命错误:在第5行的C:\ xampp \ server \ htdocs \ bridgoo \ inc \ modules \ getters.php中调用未定义的函数getComments()
可能是什么问题
答案 0 :(得分:0)
如果使用相对路径,则始终必须使用相对于包含其他文件的文件的路径。
例如,您有以下文件:
main.php
include/x.php
include/y.php
如果您通过
将x.php包含到y.php中include('x.php');
以后再加上
include('y.php');
进入你的main.php,main.php会在与main.php相同的目录中查找x.php - 它会抛出一个错误。如果你只是打电话给y.php就行了。因为相对于y.php,x.php位于同一目录中。
我建议你尽可能使用绝对路径。