-1

I have three pages: group_data.php, getters.php, and homepage.php the are all contained in two different directories;

home is in the root folder, while both group_data.php and getters.php are in the inc/modules/ sub-folder;

inc/modules/group_data.php, inc/modules/getters.php

this is the code in my group_data.php page:

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; 

}

calling the getfollowedGroupPosts() function works on the getters.php page, but including the getters.php page in homepage.php trows a the error below;

Fatal error: Call to undefined function getComments() in C:\xampp\server\htdocs\bridgoo\inc\modules\getters.php on line 5

what could be the problem

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Maxwell
  • 147
  • 2
  • 12
  • How are your scripts included in your homepage ? include, require ? – Jean-Luc Aubert Aug 21 '17 at 13:00
  • The problem is not in `group_data.php`, its in `getters.php` on line 5. – castis Aug 21 '17 at 13:00
  • my scripts uses require once – Maxwell Aug 21 '17 at 13:06
  • now, i just got a down vote, I couldn't have asked the question in a less obscured manner, i just couldn't figure out where the problem came from – Maxwell Aug 21 '17 at 13:07
  • Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[this happens](https://media.giphy.com/media/kg9t6wEQKV7u8/giphy.gif)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions and prepared statements. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Aug 21 '17 at 13:12

1 Answers1

0

If you use relative Paths, you always have to use the Path relative to the File in which the other Files are included.

For Example, you have these Files:

main.php
include/x.php
include/y.php

If you include x.php into y.php by

include('x.php');

and later you include

include('y.php');

into your main.php, main.php will look for x.php in the same Directory as main.php - it will throw an Error. If you just call y.php it will work. Because relative to y.php, x.php is in the same Directory.

I recommend you to use absolute Paths therefore, if possible.

Bernhard
  • 1,852
  • 11
  • 19
  • ya, i think thats the problem, it just worked magically, i have been at this for day now, thanks – Maxwell Aug 21 '17 at 13:11