0

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?

Anushka Agarwal
  • 127
  • 1
  • 3
  • 20

3 Answers3

1

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

  • @fastebro-its giving an error "Undefined index:tab". – Anushka Agarwal Feb 18 '14 at 06:51
  • @fastebro-can u explain how can I get tab parameter from querystring? – Anushka Agarwal Feb 18 '14 at 06:51
  • Are you sure do you have defined a tab parameter? Read official documentation: http://www.php.net/manual/it/reserved.variables.get.php –  Feb 18 '14 at 07:09
  • @fastebro- You may check my code that I have provided above. – Anushka Agarwal Feb 18 '14 at 07:11
  • In switch statement you can implement "default" key to load .php page when $_GET parameter is not defined! :) "Undefined Index" is a **warning message** (because debug configuration is enabled on your server). You can solved with "isset" function like @anurup's solution. –  Feb 18 '14 at 07:51
  • @fastebro-How may I change my setting to remove this warning? – Anushka Agarwal Feb 18 '14 at 08:27
  • You can follow the official documentation: http://www.php.net/manual/en/function.error-reporting.php or read this SO topic: http://stackoverflow.com/questions/8652933/how-to-disable-notice-and-warning-in-php-within-htaccess-file :) –  Feb 18 '14 at 08:28
  • @fastebro-I have tried the concept as provided by anurup.Now I want that initially my one php file(question.php) should be shown when my tab.php is loaded.How may I achieve this? – Anushka Agarwal Feb 18 '14 at 08:30
0

I'd just do it with if(isset($_GET['setup'])) { display setup code } seems the simple solution to me.

d.abyss
  • 204
  • 1
  • 4
  • 26
0

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');
anurupr
  • 2,294
  • 2
  • 20
  • 28