0

Hello guys,

I have a doubt regarding the tabs I have in my project. Its a user view page with multiple tabs in it. Each tab is having details like user basic info, social profile info, skills etc. The current setup is PHP tabs with $_GET['tab'] value. There are different $_GET['tab'] for each tabs and the if condition checks the $_GET['tab'] variable and loads the content of include file in that tab. There are about 10 tabs and 10 if conditions in this page.

The page itself is having other include files like header, footer, side menu etc.

Me and my friend had a discussion on this and he suggests to have separate page for each tabs and avoid if conditions in the page.

My questions are:
1) Does the number of if conditions really make changes to the performance of the page?
2) Should I switch to separate page and have visual tab look?

4
Contributors
10
Replies
61
Views
2 Years
Discussion Span
Last Post by veedeoo
0

What are you talking about? Tabs, as I understand them, can only be worked upon by javascript (with AJAX maybe). I think that you have some design which only emulates "tabs" (and every link finishes by a page request to the server). You can talk about performance issues only if you have alot of people visiting your page (site/app), and I mean ALOT...

0

I know we can setup TABs using jquery and AJAX. Some of my tabs do have AJAX in it and I don't want to make it complex with nested AJAX.
My question is regarding the TAB setup using PHP (emulating "tabs") and the performance of PHP if lots of if conditions are there.

0

Let's see:
1. |click-a-link|->|load-php-script-with-ifs-and-include-headers-footer-side-menu|->|depending-on-ifs-include-content|
2. |click-a-link|->|load-a-page-with-headers-footer-side-menu-content|

Second route seems faster, so you should switch to separate page and have visual tab look.

0

Thank you for your time Adrian,

The header, footer and side menu are include files. So the second option becomes.

2) |click-a-link|->|load-a-page-with-content|->|include-headers-footer-side-menu|

0

ok... then add a step to the first option too, and you will still get faster with second option :)

0

have you considered SEO? This may not be an issue now, but it may be later. Worth investigating. Is unique content linked to a unique url (including uses of hashes)?

0

This is for an application not for website. So I don't think SEO matters here.

0

Does the number of if conditions really make changes to the performance of the page?

probably, nobody ever study the performance of a nested if statements. Nesting them too deeply we will have the so called "spaghetti logic" , but there is hope and I can assure you it is highly recommended to use switch.

Should I switch to separate page and have visual tab look?

Have you heard about the PHP function called file_get_contents()? This can be something you want to investigate and it is binary safe.

example:

<?php 

$content1 = 'this is content one';
$content2 = 'this is content two';
$content3 = 'this is content three';
$default_content = 'This is default content';


if(isset($_GET['content']) && (!empty($_GET['content']))){

    $x = $_GET['content'];

switch ($x){
    case "content_one":
    $content = $content1;
    break;

    case "content_two":
    $content = $content2;
    break;

    case "content_three":
    $content = $content3;
    break;

    default: 

    $content = $default_content;

}

}
else{

    $content = $default_content;

}

## tabs
    echo '<h2> My PHP tab </h2>';

    echo '<a href="?content=content_one"> [ Content 1 ] </a>  |  <a href="?content=content_two"> [ Content 2 ]</a> | <a href="?content=content_three">[ Content 3 ]</a>';

    echo '<br/>';

    echo $content .'<br/>';

These

$content1 = 'this is content one';
$content2 = 'this is content two';
$content3 = 'this is content three';

can take pages like this

$content1 = file_get_contents('content1.txt');
$content2 = file_get_contents('content2.txt');
$content3 = file_get_contents('content3.txt');

to make it to work effeciently, you need to change the execution on the switch side and get rid of the above e.g.

case "content_one":
    $content =  file_get_contents('content1.txt');
    break;

that will give you the shortest distance between the text file and the user.

That is all my thoughts for the matter.

Edited by veedeoo: more info added

0

Thank you @veedeoo for your input. However I have now applied the following method to my Tabs. Do you think Switch will perform better than this one?

Code for showing Tab contents:

$tab_view = $_GET['tab']
$whitelist = array("tab1", "tab2", "tab3", "tab4");
   if (in_array($tab_view, $whitelist)) 
   {
     include 'tabdir/' . $tab_view . '.php';
   }

Code for Tab links

<ul>
<li><a href="index.php?tab=tab1">Tab1</a></li>
<li><a href="index.php?tab=tab2">Tab2</a></li>
<li><a href="index.php?tab=tab3">Tab3</a></li>
<li><a href="index.php?tab=tab4">Tab4</a></li>
</ul>
0

Your codes will work perfectly, just make sure to put a default page on it, or wrap it with

if(isset($_GET['tab']){ 

    //codes here

   }

to avoid getting the undefined variable error.

Mine will probably work best if there is a function or method involve in the process, but I am not sure because I didn't even try testing it.

Edited by veedeoo: more info added

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.