How can I modify the code in this tutorial to use a 2 dimensional array instead of a 1 dimensional array?
This would be the array I need to use.
Array
(
[27] => Array
(
[1] => Testing 3
[2] => 2008-01-01
[3] =>
This is another test for news page.
[4] =>
)
[25] => Array
(
[1] => Testing
[2] => 2007-02-01
[3] =>
BLAH!"!£!£F F ADSFA F
kskdfjfj ks kjd
[4] => doc_25.pdf
)
)
The code in that tutorial
<?php
// First of all, handle configuration ... Read in values from a GET
// and default values that don't exist:
$page = (isset($_GET['page']) && ($_GET['page'] > 0))
? intval($_GET['page']) : 1;
$view = (isset($_GET['view']) && ($_GET['view'] > 0))
? intval($_GET['view']) : 10;
// Create our fake data to paginate on, just use the alphabet
$data = range('a', 'z');
// Now, chunk the data into equal sized pieces, based upon the view.
$pages = array_chunk($data, $view, true);
// Now output the chunk of data that was asked for:
echo "<p>The results are:</p>\n<p>\n";
foreach($pages[$page - 1] as $num => $datum) {
echo $num + 1, ". {$datum}<br />\n";
}
echo "</p>\n";
// Now create the options to change what page you are viewing:
echo '<p>Switch to page: |';
$get = $_GET;
foreach(range(1, count($pages)) as $p) {
// If this is the current page:
if ($page == $p) {
echo " {$p} |";
} else {
// We need to give them their option - First generate the URL needed
// We want to duplicate any query string given to us, but replacing
// any pagination values with our new page. Easiest is to take a
// current copy of get, update it for our values, then recreate it.
$get['page'] = $p;
$query = http_build_query($get);
echo " <a href=\"{$_SERVER['PHP_SELF']}?{$query}\">{$p}</a> |";
}
}
echo "</p>\n";
// Now let's give some options to change how many results we see per page:
$options = array(3, 5, 10, 50);
// Make a new copy of the $_GET array to play with again
$get = $_GET;
// Always set page to 1 when making a change to the number of results:
unset($get['page']);
// And let's output the options in the same manner as the pages:
echo '<p>Results per page: |';
foreach($options as $o) {
// If the current option:
if ($o == $view) {
echo " {$o} |";
} else {
// Give the new option, again by regenerating the GET
$get['view'] = $o;
$query = http_build_query($get);
echo " <a href=\"{$_SERVER['PHP_SELF']}?{$query}\">{$o}</a> |";
}
}
echo "</p>\n";
?>
Thanks in advance.