简体   繁体   中英

Include php files inside tab

I have a php file tab.php which is creating tabs.The code of tab.php is:

<ul id="tabs">

<?php
$tab=' ';
if($tab=='') $tab='setup';

//$tab=$_REQUEST['tab'];


         if($tab=='setup'){ ?>
        <li><b><span>Setup</span></b></li>
        <?php 
        }else{ ?>
        <li><a href="?tab=setup"><span>Setup</span></a></li>
        <?php } ?>

        <?php if($tab=='options'){ ?>
        <li><b><span>Options</span></b></li>
        <?php }else{ ?>
        <li><a href="?tab=options"><span>Options</span></a></li>
        <?php } ?>

        <?php if($tab=='questions'){ ?>
        <li><b><span>Questions</span></b></li>
        <?php }else{ ?>
        <li><a href="?tab=questions"><span>Questions</span></a></li>
        <?php } ?>

        <?php if($tab=='flow'){ ?>
        <li><b><span>Flow</span></b></li>
        <?php }else{ ?>
        <li><a href="?tab=flow"><span>Flow</span></a></li>
        <?php } ?>



   </ul>


<div style="clear:both; background-color:#edcb27; height:0px; overflow:hidden;"></div>    
<div style="border:solid 3px #edcb27; background-color:#edcb27; padding:10px; font-family:Verdana, Geneva, sans-serif; font-size:11px;">
<label>Edit Mode</label>
<label>dfhfghj</label> 

I have four php files namely setup.php,options.php,question.php and test.php.What I want is when I click on setup tab setup.php should open.When I click on option.php then my option.php should open and so on.Initially setup.php should be visible.So where should I include my all four php files so that particular php file should be open when clicking on tab?

If your page will be refresh each time when you press a tab you can use a switch statement and get tab value from query-string:

    $tab = $_GET["tab"];
    switch ($tab) {

       case "setup":
          require "setup.php";
          break;

       default:
          break;
    }

to load a YOUR_FILENAME.php.

Other (good) solution is use a asynchronous request with jQuery or other JavaScript libraries.

Cheers

我只是用if(isset($_GET['setup'])) { display setup code }来解决这个问题。

If you are putting all your tab pages in the same folder as this code, this should do the trick

<ul id="tabs">
 <?php
    $tab='';

    if(!isset($_GET['tab'])) $tab='setup';
    else $tab = $_GET['tab'];

    //$tab=$_REQUEST['tab'];

     if($tab=='setup'){ ?>
    <li><b><span>Setup</span></b></li>
    <?php 
    }else{ ?>
    <li><a href="?tab=setup"><span>Setup</span></a></li>
    <?php } ?>

    <?php if($tab=='options'){ ?>
    <li><b><span>Options</span></b></li>
    <?php }else{ ?>
    <li><a href="?tab=options"><span>Options</span></a></li>
    <?php } ?>

    <?php if($tab=='questions'){ ?>
    <li><b><span>Questions</span></b></li>
    <?php }else{ ?>
    <li><a href="?tab=questions"><span>Questions</span></a></li>
    <?php } ?>

    <?php if($tab=='flow'){ ?>
    <li><b><span>Flow</span></b></li>
    <?php }else{ ?>
    <li><a href="?tab=flow"><span>Flow</span></a></li>
    <?php } ?>
 </ul>

<div style="clear:both; background-color:#edcb27; height:0px; overflow:hidden;"></div>    
<div style="border:solid 3px #edcb27; background-color:#edcb27; padding:10px; font-family:Verdana, Geneva, sans-serif; font-size:11px;">
<label>Edit Mode</label>
<label>dfhfghj</label>

<!-- assuming you are putting the content of the page here -->

require($tab.'.php');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM