Firstly hello all
Those who are reg contribs will probaly recognise bits of this code...
shamelessly used for my own evil ends..lol
I am using a flat file database..yes I know MySql would be better...but I dont have time or patience to log several 1000 entries ( I inherited this)
I am trying to filter by 1st letter asc then display the results...because there are so many results (900+for "a" alone)
This is the errors tthat I am getting
Invalid argument in C:\xampp\htdocs\xxxxxx\getfile7.php on line 41
Warning: array_slice() expects parameter 1 to be array, boolean given in C:\xampp\htdocs\xxxxxx\getfile7.php on line 46
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\xxxxxx\getfile7.php on line 49
here is the code I have so far:
<?php
// example [url]http://localhost/getfile2.php?filter=a[/url]
// not case sensative
$filter = $_GET["filter"]; // assign filter to var
$dirname = 'xxxxxx/public/reviews/';
//$dirname = "./";
$dir = opendir($dirname);
?>
<?php
$pattern = "/^$filter/i"; //setup pattern to be filtered
// the i makes it not case sensative, if you want it case sensative just delete the i
if ($filter) print "All files begining with $filter<BR>"; // if filter has been passed print what it is
else print "All files<BR>"; // or else print all files.
while(false != ($file = readdir($dir)))
{
if(($file != ".") and ($file != ".."))
{
if (preg_match($pattern,$file)) { // if pattern is matched at the first letter of the filename
//echo("<a href='$dirname$file'>$file</a> <br />");
$files= ("<a href='$dirname$file'>$file</a> <br />");
}
}
}
$data = file("<a href='$dirname$file'>$file</a> <br />");
$perpage = 50; //Obviously you would want to change this to something higher, depending on the content.
if(isset($_GET['start'])) $start = $_GET['start']; else $start = 0;
$numposts = count($data);
$data = array_slice($data, $start, $perpage);
foreach($data as $k => $v)
{
echo $data[$k].''."\n";
}
echo "</table>";
echo "<center>";
if($start > 0)
{
$text .= '<a href="getfile7.php?start='.($start - $perpage).'">< Previous Page </a>';
}
if($start > 0 && $numposts > $perpage && $start < $numposts - $perpage)
{
$text .= ' | ';
}
if($numposts > $perpage && $start < $numposts - $perpage)
{
$text .= '<a href="getfile7.php?start='.($start + $perpage).'">Next Page ></a>';
}
echo $text;
echo "<br>";
$numpages = ceil($numposts / $perpage);
echo "Go to Page";
for( $i=1; $i<=$numpages; $i++ )
{
$pages = ($i -1);
$advance = ($pages * $perpage);
echo "<a href=getfile7.php?start=$advance>";
$pages = ($i);
echo " ";
echo "[$pages]</a>";
echo " ";
}
echo "<br>";
echo "$numposts Tiles begin with $filter";
echo "<br>";
if(isset($_GET['start'])) $query = $_GET['start']; else $query = 0;
$query = ceil($query / $perpage);
$query = ($query +1);
echo "Page $query of $numpages";
echo "<br>";
echo "<br>";
?>
Can someone point out where I am going wrong please?
PS as you can see by the name of the file getfile7.php...I've been trying for a bit...lol