Hello PHP guru’s !
I’m an html and Wordpress person and don’t know PHP at all. I found this little text flatfile database script that I want to do something with but the listing part does not work !
Listed below is the script… and link image of the error … and link to an image of the database structure…
Any help will be appreciated…
Ta
Sam
[php]
<?php require("../config.php"); if ($enablegzip == "1") { ob_start("ob_gzhandler"); header("Content-Encoding: gzip"); } session_start(); ?>
<?php print"$sitetitle"; ?> |
LINKS
Title: | |
Link: | |
Description: | |
Your name: | |
Email: | |
Country: | |
Link Quality: | 1 2 3 4 5 |
Enter this text |
|
<? $gbfile='links.txt'; $separator= '|';
//==== This function will add one line to the end of file
function add($str){
global $gbfile;
$tmp = trim($str);
$fp=fopen($gbfile,‘a+’);
flock($fp, LOCK_EX);
fwrite($fp, $tmp. “\n”);
flock($fp, LOCK_UN);
fclose($fp);
}
//=== Function below gets specified number of lines and returns an array
function get($start, $end){
global $gbfile;
$records=array();
$filename=“links.txt”;
$fp=fopen($gbfile,‘r’);
flock($fp, LOCK_SH);
$i=1;
$tmp=TRUE;
while($i<$start && !feof($fp)) {
$tmp=fgets($fp);
$i++;
}
while($i<=$end && !feof($fp)) {
$tmp=trim(fgets($fp));
if ($tmp) { array_push($records, $tmp); }
$i++;
}
flock($fp, LOCK_UN);
fclose($fp);
return($records);
}
//======================Listing part
$start=$_GET[‘start’];
$end=$_GET[‘end’];
if (!$end || $start<=0) { $start=1; }
if (!$end) { $end=$linkspage; }
if ($end<$start) { $end=$start+1; }
$show=$end - $start;
//======================Get records from file into array
$records = get($start, $end);
//=======================For each record get each field
foreach ($records as $rec) {
$tmp = explode($separator, $rec);
$title = $tmp[0];
$link = $tmp[1];
$desc = $tmp[2];
$name = $tmp[3];
$email = $tmp[4];
$country = $tmp[5];
$rating = $tmp[6];
//================== Outputting
?>
Link: <?=$link?>
Description: <?=$desc?>
Link submitted by <?=$name?> from <?=$country?> Rating
<? } //Pagination if ($start>$show) { $start-=$show; $end-=$show; $start--; $end--; print ""; $start--; $end--; } else { print "No more records found !"; } } else { $start+=$show; $end+=$show; $start++; $end++; print ""; $start--; $end--; } ?>
<?php print"$sitefooter"; ?> |
[/php]
and the error message ! --> http://gamez.za.org/appsbar.PNG
and the layout of the database (lol… text file) – >http://gamez.za.org/appy.PNG