php - Echo the next article or previous article with urls -
the nest.php page below contains multidimensional array $laws, , contains groups of laws chapters comprise of several articles in them.
i have made previous article , next article dynamic url links echo 1 article after sequentially.
but php code should add these (2) urls skip next chapter when last article of particular chapter has been echoed?
<?php session_start(); $laws=array( "group1"=>array( "1"=>array( "1"=>"this article (1) in chapter (1) of (group1)", "2"=>"this article (2) in chapter (1) of (group1)", "3"=>"this article (3) in chapter (1) of (group1)", ), "2"=>array( "1"=>"this article (1) in chapter (2) of (group1)", "2"=>"this article (2) in chapter (2) of (group1)", "3"=>"this article (3) in chapter (2) of (group1)", ), ), "group2"=>array( "1"=>array( "1"=>"this article (1) in chapter (1) of (group2)", "2"=>"this article (2) in chapter (1) of (group2)", "3"=>"this article (3) in chapter (1) of (group2)", ), "2"=>array( "1"=>"this article (1) in chapter (2) of (group2)", "2"=>"this article (2) in chapter (2) of (group2)", "3"=>"this 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]; // articles echoed here!!!!! echo '<br/>'; ?> <!-------------- previous article , next article urls -------------------> <a href="nest.php?group=<?php echo $group; ?>&chapter=<?php echo $chapter; ?>&article=<?php echo --$previousarticle ; ?>" style="text-decoration: none;">previous article</a> <br/> <a href="nest.php?group=<?php echo $group; ?>&chapter=<?php echo $chapter; ?>&article=<?php echo ++$article ; ?>" style="text-decoration: none;">next article</a>
you can add 1 more condition before link below
<!-------------- previous article , next article urls -------------------> <?php $prvartcle = $previousarticle -1 ; if(!empty($laws[$group][$chapter][$prvartcle])) {?> <a href="test1.php?group=<?php echo $group; ?>&chapter=<?php echo $chapter; ?>&article=<?php echo --$previousarticle ; ?>" style="text-decoration: none;">previous article</a> <?php } ?> <br/> <?php $nextart = $article+1; if(!empty($laws[$group][$chapter][$nextart])) {?> <a href="test1.php?group=<?php echo $group; ?>&chapter=<?php echo $chapter; ?>&article=<?php echo ++$article ; ?>" style="text-decoration: none;">next article</a> <?php } ?>
Comments
Post a Comment