How to use php in templates

Tutorials for <a href="http://www.phpbbstyles.com/viewtopic.php?t=356">eXtreme Styles mod</a> for phpBB 2.0.

Moderator: Moderators

Postby Friends4U on Tue Mar 01, 2005 7:35 pm

TY

You rock... i did not know if i put this in the right topic, so if it was wrong i am sorry for that... i use phpbb from version 1.4 and i have never seen a better mod than what you guys made here, it's super!

Thank you again for your quick responce!
Friends4U
Registered User
Registered User
 
Posts: 4
Joined: Tue Mar 01, 2005 3:52 pm
Location: Dordrecht, Nederland

Postby SoDesperate on Sun Mar 06, 2005 12:19 am

I am so desperate about getting PHP working in my overall_header.tpl - I've spent the last 9 hours trying to get it going. I'm at my wits end!!

I just want an RSS feed to be run and display in overall_header.tpl.

The code works fine in a PHP file but not the TPL.

Code: Select all
include ('/home/x/x/x/x/htdocs/news/rss.php');
render_news("http://news.ft.com/rss/markets", true, 'news', 'news');


This is all I need to run in my TPL. You would save my life if you could get this *^*"^ to work:).

I'm running phpBB 2.0.12 & XS Mod 2.10.
SoDesperate
Registered User
Registered User
 
Posts: 2
Joined: Sun Mar 06, 2005 12:12 am

Postby PostBot on Sun Mar 06, 2005 12:42 am

Probably your code relies on global variables. But it is included inside function so all variables must be declared as global.
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby SoDesperate on Sun Mar 06, 2005 12:55 am

CyberAlien, thanks.:)

Without wanting to sound super n00b!e how would I declare global variables in that snippet?
SoDesperate
Registered User
Registered User
 
Posts: 2
Joined: Sun Mar 06, 2005 12:12 am

Postby PostBot on Sun Mar 06, 2005 1:07 am

Code: Select all
global $var1, $var2; // change it to list of global variables
include ('/home/x/x/x/x/htdocs/news/rss.php');
render_news("http://news.ft.com/rss/markets", true, 'news', 'news');

I don't know what variables are needed to be declared as global - that depends on your script.
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby Falconer on Sun Mar 27, 2005 9:44 am

Hi, experiencing some weird stuff...

I'm trying to do some includes, installed XS and receive no errors going into the XS in the admin panel, or on the front page.

However, PHP calls aren't being parsed at all, as if XS wasn't installed at all.

It's a new forum I'm trying to set up, so I can mess about a lot if need be.

The URL to the forum is:
http://www.hookedgamers.com/forums

I can see the php code in the source it generates.

I must be doing something wrong that's very obvious...
Falconer
Registered User
Registered User
 
Posts: 2
Joined: Sun Mar 27, 2005 9:38 am

Postby PostBot on Sun Mar 27, 2005 12:40 pm

This mod allows only php code that starts with <?php
It doesn't allow <? or <?PHP or anything else.
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby Falconer on Sun Mar 27, 2005 1:01 pm

Thanks CA, that solved it. Would never have guessed that solution.

Now that I have it working, I can finally say: brilliant mod, wouldn't want to do without it anymore. :) Thanks.
Falconer
Registered User
Registered User
 
Posts: 2
Joined: Sun Mar 27, 2005 9:38 am

Include code with MySQL connections?

Postby bartszyszka on Sun Apr 03, 2005 8:50 pm

What do I do if I want to include a PHP file in a .tpl that makes connections to a MySQL connection? This is a big problem for me right now. I have an include file that gets stuff from a separate MySQL database than the one phpbb is stored it. When that file gets included, phpBB starts using that database instead of its own database. Like when I click on a Forum the phpBB's front page, I get this error:

General Error

Couldn't obtain category list.

DEBUG MODE

SQL Error : 1146 Table 'DATABASE_PHPBB_ISNT_STORED_IN.forums' doesn't exist

SELECT c.cat_id, c.cat_title, c.cat_order FROM categories c, forums f WHERE f.cat_id = c.cat_id GROUP BY c.cat_id, c.cat_title, c.cat_order ORDER BY c.cat_order
Line : 154
File : functions.php


Any ideas?
bartszyszka
Registered User
Registered User
 
Posts: 8
Joined: Sun Apr 03, 2005 8:17 pm

Postby pentapenguin on Sun Apr 03, 2005 11:38 pm

Try using mysql_query() instead of phpBB's db functions.
User avatar
pentapenguin
Moderator
Moderator
 
Posts: 1466
Joined: Tue Sep 14, 2004 4:15 pm
Location: Georgia, USA

Postby starbanter on Sat Apr 23, 2005 6:25 am

I installed this patch but I can't get my php code to work. Here it is:

<?php

srand((double)microtime()*1000000);
$randomtopic = rand(0,5);

if ($randomtopic == "0") {
header('Location: http://www.mabus.biz/alexa0.php');

} else if ($randomtopic == "1") {
header('Location: http://www.mabus.biz/alexa1.php');

} else if ($randomtopic == "2") {
header('Location: http://www.mabus.biz/alexa2.php');

} else if ($randomtopic == "3") {
header('Location: http://www.mabus.biz/alexa3.php');

} else if ($randomtopic == "4") {
header('Location: http://www.mabus.biz/alexa4.php');

} else if ($randomtopic == "5") {
header('Location: http://www.mabus.biz/alexa5.php');

} else {
echo ( "ERROR: There was a problem running the script.
");
}
?>

I'm trying to get this to work in overall_footer.tpl

Can you help me figure out what I am doing wrong and need to do to make it work?
starbanter
Registered User
Registered User
 
Posts: 5
Joined: Sat Apr 23, 2005 6:22 am

Postby PostBot on Sat Apr 23, 2005 9:15 am

This would be a better code:
Code: Select all
<?php

$randomtopic = mt_rand(0,5);
header('Location: http://www.mabus.biz/alexa' . $randomtopic . '.php');

?>


But it won't work in overall_footer.tpl because header() function should be used before any output and output already started in overall_header.tpl. What exactly are you trying to do?
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby starbanter on Sat Apr 23, 2005 7:31 pm

I have a number of files I want to call into the footer, each with different links on them. I want it to be randomly determined (equal odds), which is called onto a given page. That is what I am trying to do. Is there a better way to do this?
starbanter
Registered User
Registered User
 
Posts: 5
Joined: Sat Apr 23, 2005 6:22 am

Postby starbanter on Sat Apr 23, 2005 7:32 pm

I should clarify that I am only trying to pull one of these files per page. Just a random selection among a group of very similar include files.
starbanter
Registered User
Registered User
 
Posts: 5
Joined: Sat Apr 23, 2005 6:22 am

Postby PostBot on Sat Apr 23, 2005 7:59 pm

Function header() is used to send http headers, not link to something. And header('Location: blah') is used to redirect whole page.

So use code like this:
Code: Select all
<?php
$randomtopic = mt_rand(0,5);
readfile('http://www.mabus.biz/alexa' . $randomtopic . '.php');
?>
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

PreviousNext

Return to eXtreme Styles mod tutorials

Who is online

Users browsing this forum: No registered users and 2 guests

cron