I have this file that gets a list of news articles. I named it news.inc.php Now, I try to call this file from another file and it prints out the code instead of the list of articles. Is there a way I could do this? I tried fread, fopen and get_file_contents but doesn’t seem to work.
Can anyone please help me?
Function
function news($tablename, $title, $content, $date)
{
$list = '<div style="border:1px solid #CCC;">';
$query = 'SELECT * FROM '.$tablename;
$result = mysql_query($query);
if(!$result)
{
return 'Query failed on select: '.mysql_error();
exit();
}
while($row = mysql_fetch_array($result))
{
$list .= '<p><a href="news.php?id="'.$row['id'].'>'.$row[$title].'</a><br />';
list($year, $month, $day)=split('-', $row[$date]);
$list .= date('F j, Y', mktime(0,0,0,$month,$day,$year)).'</p>';
}
$list .= '</div>';
return $list;
}
news.inc.php
$tablename = 'news';
$title = 'subject';
$content = 'content';
$date = 'datemodified';
news($tablename, $title, $content, $date);