Grow your CSS skills. Land your dream job.

PHP dynamic content

  • # September 3, 2012 at 7:43 am

    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 == 'home'){
    include ('subcontent/home.php');
    include ('content/home.php');
    }
    else if ($_GET == 'webdev'){
    include ('subcontent/webdev.php');
    include ('content/webdev.php');
    }
    else if ($_GET == 'software'){
    include ('subcontent/software.php');
    include ('content/software.php');
    }
    else if ($_GET == 'websites'){
    include ('subcontent/websites.php');
    include ('content/websites.php');
    }
    else if (!empty($_GET) ){
    include ('error.php');
    header( 'refresh: 6; url=index.php');
    }
    ?>
    # September 3, 2012 at 3:41 pm

    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 ){
    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;
    }
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".