2013-02-16 2 views
0

NEXT ARTICLE url 링크에 어떤 PHP 코드를 추가해야하나요? 그러면 다음에 나오는 기사가 나중에 다시 표시 되나요?URL 링크에 PHP 코드 추가

순차적으로 하나의 기사를 에코하려는 것입니다.

감사합니다.

(form.php)

<form action="process.php" method="get"> 
    Group: 
    <select name="group"> 
     <option value="group1">Group1</option> 
     <option value="group2">Group2</option> 
    </select> 

    Chapter: 
    <input type="text" name="chapter"> 

    Article: 
    <input type="text" name="article"> 

    <input type="submit" value="Go to Article">  

</form> 

(process.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)", 
           ), 

     ) 
     ); 

$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> 
+1

'$ _SESSION [ '기사'= $ _GET [ '기사']] '행운을 빕니다가 할당. –

+0

다음 기사가 무엇인지 어떻게 결정합니까? –

+0

@ Jan-Henk :'$ _SESSION [ 'nextarticle'= $ _GET [ 'nextarticle']];'분명히. – FtDRbwLXw6

답변

0

는 다음 기사는 불분명하다 그 무엇, 그리고 당신은 오류가 (내 의견을 참조)로 보이는이

링크가 기사를로드하도록 코드를 업데이트했습니다 (하지만 다음 기사가 아닐 수도 있습니다). 답을 찾는 길에 아마이 것 이상의 도움을 ...

<?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> 
+0

다시 한 번 친절하게이 코드를 살펴보십시오. – user2075752

+0

편집보기 – Tucker

0

당신은에 가서 많이 부여하지 않은,하지만 $_GET['article'] 가정 것은 문서 번호를 있어야하는데, 당신은 단지 증가 할 그것은 1 (당신의 기사가 순차적 가정) :

<a href="process.php?article=<?php echo (int)$_GET['article'] + 1; ?>" style="text-decoration: none;">NEXT ARTICLE</a>