Why am i getting this Smarty error?
Posted: Sat May 29, 2004 6:08 pm
the error
index.php
and functions.php
I get that error
but i dont get it when i dont put the display post code as a function in an included file. like this:
what am i doing wrong?
if i make the posts diplay code into a function like thisFatal error: Call to a member function on a non-object in C:\Apache2\htdocs\yorov3\functions.php on line 21
index.php
Code: Select all
<?
session_start();
require_once("libs.inc.php");
include 'db.php';
include 'functions.php';
if(isset($_SESSION['username'])){
$username = $_SESSION['username'];
}
display_news();
if(empty($_SESSION['username']))
{
$smarty->assign("logged_in", 0);
} else {
$smarty->assign("logged_in", 1);
}
$smarty->display("index.html");
?>Code: Select all
<?
function redirect($url) {
echo "<script language="Javascript">
window.location="$url"
</script>";
}
function display_news()
{
$sql = mysql_query("select * from news");
if(mysql_num_rows($sql) >= 1)
{
$news = array();
while($rows = mysql_fetch_array($sql, MYSQL_ASSOC))
{
array_push($news, $rows);
}
$smarty->assign("news", $news);
} else {
$smarty->assign("news", 0);
}
}but i dont get it when i dont put the display post code as a function in an included file. like this:
Code: Select all
<?
session_start();
require_once("libs.inc.php");
include 'db.php';
if(isset($_SESSION['username'])){
$username = $_SESSION['username'];
}
$sql = mysql_query("select * from news");
if(mysql_num_rows($sql) >= 1)
{
$news = array();
while($rows = mysql_fetch_array($sql, MYSQL_ASSOC))
{
array_push($news, $rows);
}
$smarty->assign("news", $news);
} else {
$smarty->assign("news", 0);
}
if(empty($_SESSION['username']))
{
$smarty->assign("logged_in", 0);
} else {
$smarty->assign("logged_in", 1);
}
$smarty->display("index.html");
?>