treehouse : what would you like to learn today?
Web Design Web Development iOS Development

PHP dynamic content

  • I've figured out my own way to load dynamic content with PHP and it works fairly well. I just want to know how I can stop the page from 'flashing white' each time the content is changed. Feel free to suggest any ways how I could do this better.

    Here's a snippet:

    <?php
    if(empty($_GET)){
    include ('subcontent/home.php');
    include ('content/home.php');
    }
    else if ($_GET ['content'] == 'home'){
    include ('subcontent/home.php');
    include ('content/home.php');
    }
    else if ($_GET ['content'] == 'webdev'){
    include ('subcontent/webdev.php');
    include ('content/webdev.php');
    }
    else if ($_GET ['content'] == 'software'){
    include ('subcontent/software.php');
    include ('content/software.php');
    }
    else if ($_GET ['content'] == 'websites'){
    include ('subcontent/websites.php');
    include ('content/websites.php');
    }
    else if (!empty($_GET) ){
    include ('error.php');
    header( 'refresh: 6; url=index.php');
    }
    ?>
  • when you describe "flashing white" I suspect you're just seeing the page reload. You could set it up to joad via AJAX (don't reload the page; just get new content). I know Chris has an AJAX demo (or maybe blog entry) somewhere.

    tangent - you current code would benefit from the switch statement:
    <?php
    switch( @$_GET['content'] ){
    case 'webdev':
    include ('subcontent/webdev.php');
    include ('content/webdev.php');
    break;
    case 'software':
    include ('subcontent/software.php');
    include ('content/software.php');
    break;
    case 'websites':
    include ('subcontent/websites.php');
    include ('content/websites.php');
    break;
    default:
    include ('subcontent/home.php');
    include ('content/home.php');
    break;
    }