gpalmer711
IS-IT--Management
Hi All,
Sorry if this is a little basic but I am quite new to PHP.
I'm currently trying to make a custom front page for a clients phpBB forum and am going through the PHP code and using what I need.
I have the code working as I want it to, but now i'm trying to streamline the page so that it loads faster. There is a block of code that is being used over and over so I wanted to put it into a function. However when I try I get various errors, I think that these are relating to variables that are declared in files that are included using the include statement. Here's the code
It errors out on this line
The error code is
So i tried adding the code
at the start of the original block. Then get the following error
which relates to the number 1 at the end of my SQL statement.
So I guess what I am really asking is, is this just a silly noob question from not understanding functions correctly in PHP or something else?
Thanks for looking
Greg Palmer
Freeware Utilities for Windows Administrators.
Sorry if this is a little basic but I am quite new to PHP.
I'm currently trying to make a custom front page for a clients phpBB forum and am going through the PHP code and using what I need.
I have the code working as I want it to, but now i'm trying to streamline the page so that it loads faster. There is a block of code that is being used over and over so I wanted to put it into a function. However when I try I get various errors, I think that these are relating to variables that are declared in files that are included using the include statement. Here's the code
Code:
function greg($forum_id){
$sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_username, p2.post_username AS post_username2, p2.post_time
FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u2
WHERE t.forum_id = $forum_id
AND t.topic_poster = u.user_id
AND p.post_id = t.topic_first_post_id
AND p2.post_id = t.topic_last_post_id
AND u2.user_id = p2.poster_id
AND t.topic_type <> " . POST_ANNOUNCE . "
AND t.topic_type <> " . POST_STICKY . "
$limit_topics_time
ORDER BY t.topic_type DESC, t.topic_last_post_id DESC
LIMIT $start, 1";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain topic information', '', __LINE__, __FILE__, $sql);
}
}
It errors out on this line
Code:
if ( !($result = $db->sql_query($sql)) )
The error code is
Code:
Fatal error: Call to a member function sql_query() on a non-object in c:\Inetpub\[URL unfurl="true"]wwwroot\phpBB2\greg1.php[/URL] on line 59
So i tried adding the code
Code:
global $db;
at the start of the original block. Then get the following error
Code:
SQL Error : 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 1' at line 12
which relates to the number 1 at the end of my SQL statement.
So I guess what I am really asking is, is this just a silly noob question from not understanding functions correctly in PHP or something else?
Thanks for looking
Greg Palmer
Freeware Utilities for Windows Administrators.