向url链接添加php代码

向url链接添加php代码,php,Php,我应该在下面的下一篇文章url链接中添加哪些php代码,以使下一篇文章随后得到回音 我打算依次复述一篇又一篇文章 谢谢大家! (form.php) 组: 第一组 第2组 第章: 第条: (process.php) 不清楚下一篇文章是什么,而且您似乎有错误(请参阅我的评论) 我已经更新了您的代码,这样链接将加载一篇文章(但可能不是下一篇文章)。也许这至少会帮助你找到答案 <?php // $_GET['group'] receives a string // $

我应该在下面的下一篇文章url链接中添加哪些php代码,以使下一篇文章随后得到回音

我打算依次复述一篇又一篇文章

谢谢大家!

(form.php)


组:
第一组
第2组
第章:
第条:
(process.php)


不清楚下一篇文章是什么,而且您似乎有错误(请参阅我的评论)

我已经更新了您的代码,这样链接将加载一篇文章(但可能不是下一篇文章)。也许这至少会帮助你找到答案

    <?php

    // $_GET['group'] receives a string
    // $_GET['chapter'] receives a number
    // $_GET['article'] receives a number


    $_SESSION['group'] = $_GET['group'];
    $_SESSION['chapter'] = $_GET['chapter'];

        // this line here doesn't really make sense....
        //$_SESSION['article' = $_GET['article']];  
        //so perhaps you mean:
        $_SESSION['article'] = $_GET['article'];  

        $group = $_SESSION['group'];
        $chapter = $_SESSION['chapter'];
        $article = $_SESSION['article'];


        echo $group . " " . $chapter . " " . $article . "<br/>";

        $group_num = preg_replace("[^0-9]","",$group); //get the number of the group by removing everying in the string `$group` that is not a number (leaving just the number)

        $next_article_data = array();
        if(isset($laws[$group][$chapter][$article+1])){
             $next_article_data['group'] = $group;
             $next_article_data['chapter'] = $chapter;
             $next_article_data['article'] = $article+1;
        }else if(isset($laws[$group][$chapter+1][1])){
             $next_article_data['group'] = $group;
             $next_article_data['chapter'] = $chapter+1;
             $next_article_data['article'] = 1;
        else if (isset($laws["group".($group_num+1)][1][1])){
             $next_article_data['group'] = "group".($group_num+1);
             $next_article_data['chapter'] = 1;
             $next_article_data['article'] = 1;
        else
            echo "NO NEXT ARTICLE!";


        ?>

        <a href="process.php<?php 

        //I added this to pass article info in the url
        echo "?".http_build_query($next_article_data); 
        ?>" style="text-decoration: none;">NEXT ARTICLE</a>

您没有给出太多的信息,但是假设
$\u GET['article']
应该是一个文章编号,您只需将其增加1(假设您的文章是连续的):



$\u会话['article'=$\u获取['article']祝你好运。你如何确定下一篇文章是什么?@Jan Henk:
$\u SESSION['nextarticle'=$\u GET['nextarticle']显然。该代码段的语法错误。。。
<?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)",
                                ),

       )
       );

$grp= $_GET['group'];
$chap = $_GET['chapter'];
$art = $_GET['article'];

if(isset($laws[$grp]) && isset($laws[$grp][$chap]) && isset($laws[$grp][$chap][$art])){
$_SESSION['group'] = $grp;
$_SESSION['chapter'] = $chap;
$_SESSION['article'] = $art;    
}else{
$_SESSION['group'] = 'group1';
$_SESSION['chapter'] = '1';
$_SESSION['article'] = '1';   
}

$group = $_SESSION['group'];
$chapter = $_SESSION['chapter'];
$article = $_SESSION['article'];


echo $laws[$group][$chapter][$article]; // ALL NEXT ARTICLES TO BE ECHOED HERE!!!!!

?>

<a href="process.php" style="text-decoration: none;">NEXT ARTICLE</a>
    <?php

    // $_GET['group'] receives a string
    // $_GET['chapter'] receives a number
    // $_GET['article'] receives a number


    $_SESSION['group'] = $_GET['group'];
    $_SESSION['chapter'] = $_GET['chapter'];

        // this line here doesn't really make sense....
        //$_SESSION['article' = $_GET['article']];  
        //so perhaps you mean:
        $_SESSION['article'] = $_GET['article'];  

        $group = $_SESSION['group'];
        $chapter = $_SESSION['chapter'];
        $article = $_SESSION['article'];


        echo $group . " " . $chapter . " " . $article . "<br/>";

        $group_num = preg_replace("[^0-9]","",$group); //get the number of the group by removing everying in the string `$group` that is not a number (leaving just the number)

        $next_article_data = array();
        if(isset($laws[$group][$chapter][$article+1])){
             $next_article_data['group'] = $group;
             $next_article_data['chapter'] = $chapter;
             $next_article_data['article'] = $article+1;
        }else if(isset($laws[$group][$chapter+1][1])){
             $next_article_data['group'] = $group;
             $next_article_data['chapter'] = $chapter+1;
             $next_article_data['article'] = 1;
        else if (isset($laws["group".($group_num+1)][1][1])){
             $next_article_data['group'] = "group".($group_num+1);
             $next_article_data['chapter'] = 1;
             $next_article_data['article'] = 1;
        else
            echo "NO NEXT ARTICLE!";


        ?>

        <a href="process.php<?php 

        //I added this to pass article info in the url
        echo "?".http_build_query($next_article_data); 
        ?>" style="text-decoration: none;">NEXT ARTICLE</a>
<a href="process.php?article=<?php echo (int)$_GET['article'] + 1; ?>" style="text-decoration: none;">NEXT ARTICLE</a>