Hey i have a little script that list headlines.
The SQL code is inside of a php file and i made it into a php class to try and get it working. it looks as follows...
<?
class headlineClass{
function listHeadlines($tpath, $c, $lim) {
// Automatically get $tpath to avoid possible security holes
$tpath = realpath(__FILE__);
$tpath = substr($tpath,0,strrpos($tpath,DIRECTORY…
// Check if the file exists on local server and include it
if(file_exists($tpath . "cn_config.php")) {
require_once($tpath . "cn_config.php");
} else {
die("Could not include required configuration file");
}
// Check if a connection to the database was established
if(!isset($link)) {
die("Please make sure the \"\$tpath\" variable is the root path to where 'headlines.php' is on your server.");
}
// Set limit for number of items displayed
if(!isset($lim)) { $lim = "5"; }
$result = mysql_query("SELECT * FROM $t_news WHERE cat = '$c' ORDER BY date DESC LIMIT 0, $lim", $link);
echo "<ul>";
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
// HTML OUTPUT................
echo "<li>" . $row['subject'] . "</li>";
}
echo "</ul>";
mysql_free_result($result);
mysql_close($link);
}
}
?>
So on a seperate file where i want the headlines displayed a make a class and the headlines are listed. The call is as follows...
<?php include("path/allHeadlines.php"); ?>
<?php $testClass = new headlineClass(); $testClass->listHeadlines("path/",8, 1 ); ?>
But when i want to do make another class thats exactly the same by doing this...
<?php $testClass1 = new headlineClass(); $testClass1->listHeadlines("path/",8, 1 ); ?>
<?php $testClass2 = new headlineClass(); $testClass2->listHeadlines("path/",8, 1 ); ?>
The first call always works, but the second time round it seems my path is blocked and i cant get back to the database and list the items again?
Can anyone see why? The errors comes at if(!isset($link)) { and the echos
Please make sure the \"\$tpath\" variable is the root path to where 'headlines.php' is on your server.
The SQL code is inside of a php file and i made it into a php class to try and get it working. it looks as follows...
<?
class headlineClass{
function listHeadlines($tpath, $c, $lim) {
// Automatically get $tpath to avoid possible security holes
$tpath = realpath(__FILE__);
$tpath = substr($tpath,0,strrpos($tpath,DIRECTORY…
// Check if the file exists on local server and include it
if(file_exists($tpath . "cn_config.php")) {
require_once($tpath . "cn_config.php");
} else {
die("Could not include required configuration file");
}
// Check if a connection to the database was established
if(!isset($link)) {
die("Please make sure the \"\$tpath\" variable is the root path to where 'headlines.php' is on your server.");
}
// Set limit for number of items displayed
if(!isset($lim)) { $lim = "5"; }
$result = mysql_query("SELECT * FROM $t_news WHERE cat = '$c' ORDER BY date DESC LIMIT 0, $lim", $link);
echo "<ul>";
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
// HTML OUTPUT................
echo "<li>" . $row['subject'] . "</li>";
}
echo "</ul>";
mysql_free_result($result);
mysql_close($link);
}
}
?>
So on a seperate file where i want the headlines displayed a make a class and the headlines are listed. The call is as follows...
<?php include("path/allHeadlines.php"); ?>
<?php $testClass = new headlineClass(); $testClass->listHeadlines("path/",8, 1 ); ?>
But when i want to do make another class thats exactly the same by doing this...
<?php $testClass1 = new headlineClass(); $testClass1->listHeadlines("path/",8, 1 ); ?>
<?php $testClass2 = new headlineClass(); $testClass2->listHeadlines("path/",8, 1 ); ?>
The first call always works, but the second time round it seems my path is blocked and i cant get back to the database and list the items again?
Can anyone see why? The errors comes at if(!isset($link)) { and the echos
Please make sure the \"\$tpath\" variable is the root path to where 'headlines.php' is on your server.