Generating links for multidimensional array elements and values

wert2003

New Member
The nest.php page contains all the code below.The purpose of this page is to echo back one article after another sequencially using the PREVIOUS ARTICLE and NEXT ARTICLE url links on the bottom part of the page.So far the code in the PREVIOUS and NEXT article links only goes from one article to the other within a particular chapter. This code does not allow to jump to the next chapter with the first article when the last article of a chapter has been reached, also does not allow to jump to the previous chapter with its last article when the first article of a chapter has been reached.QUESTIONHow should I alter the code in the (2) url links in nest.php to enable:(1) a jumping to the first article of the next chapter when the last article of a chapter is reached and;(2) jumping to the last article of the previous chapter when the first article of a chapter is reached?Thanks!\[code\]<?phpsession_start();$laws=array( "group1"=>array( "1"=>array( "1"=>"This is article (1) in chapter (1) of (group1)", "2"=>"This is article (2) in chapter (1) of (group1)", "3"=>"This is article (3) in chapter (1) of (group1)", ), "2"=>array( "1"=>"This is article (1) in chapter (2) of (group1)", "2"=>"This is article (2) in chapter (2) of (group1)", "3"=>"This is article (3) in chapter (2) of (group1)", ), ), "group2"=>array( "1"=>array( "1"=>"This is article (1) in chapter (1) of (group2)", "2"=>"This is article (2) in chapter (1) of (group2)", "3"=>"This is article (3) in chapter (1) of (group2)", ), "2"=>array( "1"=>"This is article (1) in chapter (2) of (group2)", "2"=>"This is article (2) in chapter (2) of (group2)", "3"=>"This is article (3) in chapter (2) of (group2)", ), ) );if(isset($_GET['group']) && isset($_GET['chapter']) && isset($_GET['article'])){$grp = $_GET['group'];$chap = $_GET['chapter'];$art = $_GET['article']; }else{$grp = 'group1';$chap = '1';$art = '1'; }if(isset($laws[$grp][$chap][$art])){$_SESSION['group'] = $grp;$_SESSION['chapter'] = $chap;$_SESSION['article'] = $art; }$group = $_SESSION['group'];$chapter = $_SESSION['chapter'];$article = $_SESSION['article'];$previousarticle = $_SESSION['article'];echo $laws[$group][$chapter][$article]; // ALL ARTICLES TO BE ECHOED HERE!!!!!echo '<br/>';?> <!-- PREVIOUS ARTICLE & NEXT ARTICLE LINKS BELOW --> <br/><a href="http://stackoverflow.com/questions/15888743/nest.php?group=<?php echo $group; ?>&chapter=<?php echo $chapter; ?>&article=<?php echo --$previousarticle ; ?>" style="text-decoration: none;">PREVIOUS ARTICLE</a><br/><a href="http://stackoverflow.com/questions/15888743/nest.php?group=<?php echo $group; ?>&chapter=<?php echo $chapter; ?>&article=<?php echo ++$article ; ?>" style="text-decoration: none;">NEXT ARTICLE</a>\[/code\]
 
Top