Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用URL回显下一篇文章或上一篇文章_Php_Html_Xhtml - Fatal编程技术网

Php 使用URL回显下一篇文章或上一篇文章

Php 使用URL回显下一篇文章或上一篇文章,php,html,xhtml,Php,Html,Xhtml,下面的nest.php页面包含一个多维数组$laws,它包含组,其中包含由多篇文章组成的章节 我制作了上一篇文章和下一篇文章的动态url链接,以按顺序回显一篇又一篇文章 但是,当某一章的最后一篇文章被回响时,我应该向这些(2)URL添加什么PHP代码以跳到下一章 <?php session_start(); $laws=array( "group1"=>array( "1"=>array(

下面的nest.php页面包含一个多维数组$laws,它包含,其中包含由多篇文章组成的章节

我制作了上一篇文章下一篇文章的动态url链接,以按顺序回显一篇又一篇文章

但是,当某一章的最后一篇文章被回响时,我应该向这些(2)URL添加什么PHP代码以跳到下一章

<?php
session_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 and 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>



您可以在链接之前添加一个条件,如下所示

<!-------------- PREVIOUS Article and 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 } ?>



所有必要的注释都会在必要时写入

<?php

$no_of_groups = count($laws);
// counting number of groups in laws

/* check if there is any selected by any user or by link. If there is nothing selected, do select first group in laws automatically */
if (isset($_GET['group']) and !empty($_GET['group'])) {
    $fgroup = $_GET['group'];
} else {
    $fgroup = $laws[0]; // selects first group in laws
}

/* check if there is any article selected by user or by link. If there is nothing selected, do select first article in a group automatically */
if (isset($_GET['article']) and !empty($_GET['article'])) {
    $farticle = $_GET['article'];
} else {
    $farticle = $fgroup[0];     // selects first article in a group
}

$no_of_article_in_this_group = count($farticle);
// counting number of article in selected or default group


/* Now, we are checking if there is chapters selected by user or by link. If there is nothing selected, do select first chapter in an article */
if (isset($_GET['chap']) and !empty($_GET['chap'])) {
    $fchap = $_GET['chap'];
} else {
    $fchap = $farticle[0];      // selects first chapter in an article
}

$no_of_chapters_in_this_article = count($fchap);
// counting number of chapter in selected article or default article

$page_url = "nest.php";

/* We are checking, is there is next chapter available in an article, if yes then move to next chapter in an array else we will be current chapter */

if (!empty(next($fchap))) {
    $nxt_chapter = next($fchap);
} else {
    $nxt_chapter = current($fchap);
}

/* We are checking, is there is previous chapter available in an article, if yes then move to previous chapter in an array else we will be current chapter */

if (!empty(prev($fchap))) {
    $prv_chapter = prev($fchap);
} else {
    $prv_chapter = current($fchap);
}


// Below, making next and prev links ready to use

$page_next_url = $page_url . "?group=$fgroup&article=$farticle&chap=$nxt_chapter";
$page_prev_url = $page_url . "?group=$fgroup&article=$farticle&chap=$prv_chapter";


?>


如果您需要更多信息,请告诉我

这可能是答案,但您需要遮光。这个多维数组有**组=>章节=>文章**