the error
Fatal error: Call to a member function on a non-object in C:\Apache2\htdocs\yorov3\functions.php on line 21
if i make the posts diplay code into a function like this
index.php
<?
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");
?>
and functions.php
<?
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);
}
}
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:
<?
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");
?>
what am i doing wrong?