包括php文件取决于点击了哪个链接?

时间:2015-02-16 13:34:57

标签: php

我试图在我的页面attach.php中包含几个不同的php包含文件,根据点击的链接,一次显示1个包含文件。

这是我的链接:

 <a href="attach.php?tab=insurance"><div class="hewden_square"></div><h33>Insurance Documents</h33></a> 
 <a href="attach.php?tab=policy"><div class="hewden_square"></div><h33>Policy Documents</h33></a>  

接下来,我有我的PHP代码,用于检查已点击的链接。

    <?php
switch(isset($_GET['tab'])) { //switch is just like a bunch of if()s
    default: //default case
    case '': //default case
    include('include/attachments_overview.php'); //include page.html
    break;  //break, witch means stop
    case 'insurance': // page2, if changePage has the value of page2
    include('include/upload_insurance/upload_files.php'); //include page2.html
    break;  //break, witch means stop
    case 'policy': // page2, if changePage has the value of page2
    include('include/upload_policy/upload_files.php'); //include page2.html
    break; //stop it
} //end the switch
?> 

我的默认包含文件应该在点击任何链接之前显示,这是:

include('include/attachments_overview.php'); 

然后应该包含一个或另一个,具体取决于点击的链接。 出于某种原因,我的默认包含文件显示为预期,而我的其他包含文件

include('include/upload_insurance/upload_files.php'); 
单击链接attach.php?tab = insurance

时会显示

然而,当我点击我的上一个链接attach.php?tab = policy时,这似乎只显示了我的保险标签的相同包含文件

include('include/upload_insurance/upload_files.php'); 

有人可以告诉我哪里出错了或者向我展示一个更好/更可靠的方法吗?感谢

1 个答案:

答案 0 :(得分:1)

<?php
$tb = isset($_GET['tab']) ? $_GET['tab'] : '';
switch($tb) { //switch is just like a bunch of if()s
    default: //default case
    include('include/attachments_overview.php'); //include page.html
    break;  //break, witch means stop
    case 'insurance': // page2, if changePage has the value of page2
    include('include/upload_insurance/upload_files.php'); //include page2.html
    break;  //break, witch means stop
    case 'policy': // page2, if changePage has the value of page2
    include('include/upload_policy/upload_files.php'); //include page2.html
    break; //stop it
} //end the switch
?>