Hello. Pretty new to PHP(and any sort of programming), I've been trying to modify this script that was originally written to display mysql data so it will paginate images from a directory. The code below is simplified to just show the filenames so I could see the structure more clearly. I can get the initial page "index4.php" to show up with the first 8 filenames, but when I attempt to proceed by clicking one of the page links I get this error:
Warning: array_slice() [function.array-slice]: The first argument should be an array in C:\Documents and Settings\Owner\My Documents\Websites\samcalef\test\images4.php on line 44
Although the page links do proceed accordingly, I don't get get any content. [HTML]Line 44 is in quotes[/HTML]
Here's the code and thanks in advance for any help:
<?
// Test to see if $_GET gets passed:
echo '<pre>'; print_r($_GET); echo '</pre>';
// Number of records to show per page:
$display = 8;
// Determine how many pages there are:
if (isset($_GET['np'])) { // Already been determined.
$num_pages = $_GET['np'];
} else { // Need to determine.
// Open the directory:
$handle = opendir('uploads/');
while (false !== ($file = readdir($handle))) {
$files[] = $file;
}
$num_records = count($files); // Get number of files in directory.
closedir($handle);// Close the directory.
// Calculate the number of pages.
if ($num_records > $display) { // More than 1 page.
$num_pages = ceil ($num_records/$display);
} else {
$num_pages = 1;
}
}// End of np else.
// Recieve file #.
if (isset($_GET['s'])) {
$start = $_GET['s'];
} else {
$start = 0;
}
$list = array_slice($files, $start, $display);
print_r($list);
if ($num_pages > 1) {
echo '<br /><p>';
// Determine what page the script is on.
$current_page = ($start/$display) + 1;
// If it's not the first page, make a Previous button.
if ($current_page != 1) {
echo '<a href="images4.php?s=' . ($start - $display) . '&np=' . $num_pages . '">Previous</a> ';
}
// Make all the numbered pages.
for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $current_page) {
echo '<a href="images4.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '">' . $i . '</a> ';
} else {
echo $i . ' ';
}
}
// If it's not the last page, make a Next button.
if ($current_page != $num_pages) {
echo '<a href="images4.php?s=' . ($start + $display) . '&np=' . $num_pages . '">Next</a>';
}
echo '</p>';
}
?>