Fatal Error when connecting to database using same connection

Discussion forum for MOD Writers regarding MOD Development.
Locked
ettrick
Registered User
Posts: 81
Joined: Wed Nov 21, 2012 6:45 pm
Contact:

Fatal Error when connecting to database using same connection

Post by ettrick » Wed Aug 26, 2015 8:46 pm

I'm trying to display the latest topics in the footer. Here's the code that I have so far in the overall_footer.html:

Code: Select all

<!-- PHP -->
   $result = $db->sql_query($sql);
   while ($row1 = $db->sql_fetchrow($result)){
    ('SELECT *
FROM  phpbb_topics 
WHERE topic_approved = 1 ORDER BY `topic_id` ASC
LIMIT 5' );
}
<!-- ENDPHP -->
<h2><a href="#">Latest Topics</a></h2>
<ul>
<!-- PHP -->
while ($row1 = mysql_fetch_row($result)) { <!-- ENDPHP -->
<li>  
<div><a href="<?php echo $row1['topic_url']; ?><?php echo $row1['topic_id']; ?>.html"><?php echo $row1['topic_title']; ?></a></div>
<!-- PHP --> } <!-- ENDPHP -->
</li>
</ul>
But I keep getting this error message:

Code: Select all

Fatal error: Call to a member function sql_query() on a non-object in /home2/ettrick31/public_html/forums/cache/tpl_prosilver_overall_footer.html.php on line 19
I'm trying to use the same database connection instead of creating a new one, I would assume that I'm not connecting to the database properly. I'm still new to all of this so any help at all would be appreciated.
Last edited by Oyabun1 on Wed Aug 26, 2015 9:16 pm, edited 1 time in total.
Reason: Moved from 3.0.x Support forum

User avatar
AmigoJack
Registered User
Posts: 5602
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Fatal Error when connecting to database using same connection

Post by AmigoJack » Fri Aug 28, 2015 9:33 am

$db does not exist anymore when executing the template code. Don't mix up PHP with phpBB and ask yourself why you won't find any template file that makes use of a PHP block (but instead all the PHP files exist).

Or copy what phpBB does: it uses in its footer template the {RUN_CRON_TASK} variable. Search all files for that name and you'll find /includes/functions.php and its function page_footer() - do your stuff in there and assign your variable(s) to the template.
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
The problem is probably not my English but you do not want to understand correctly.
...
We will not come anybody anyway, nevertheless, it's best to shit this.

Locked

Return to “[3.0.x] MOD Writers Discussion”